python爬虫基础(requests、BeautifulSoup)

抽屉网实现批量点赞

 1 from selenium import webdriver
 2 import urllib
 3 from urllib.request import urlopen
 4 from  bs4 import BeautifulSoup
 5 import re
 6 import time,datetime
 7 import random
 8 
 9 # pages=set()
10 # def getlinks(pageurl):
11 #     html = urlopen("http://en.wikipedia.org"+pageurl)
12 #     bsobj = BeautifulSoup(html,'html.parser')
13 #     links = bsobj.find_all('a',href=re.compile(r'^(/wiki/)'))
14 #     for link in links:
15 #         print(link['href'])
16 #
17 # getlinks('')
18 import requests
19 headers={
20         'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4882.400 QQBrowser/9.7.13059.400',
21     }
22 
23 
24 resoponse_1 = requests.get(url='https://dig.chouti.com/',
25                            headers=headers
26                            )
27 cookie_dict = resoponse_1.cookies.get_dict()
28 
29 resoponse_2 = requests.post(
30     url='https://dig.chouti.com/login',
31     data={
32         'phone':'8615733239039',
33         'password':'woshinidie',
34         'oneMonth':'1',
35     },
36     headers=headers,
37     cookies=cookie_dict
38 )
39 for page in range(1,3):
40     html = requests.get(url='https://dig.chouti.com/all/hot/recent/{}'.format(page),headers=headers)
41     soup = BeautifulSoup(html.text,'html.parser')
42     divs = soup.find(name='div',id='content-list')
43     items = divs.find_all(attrs={'class':'item'})
44     for i in items:
45         click_id = i.find('img').get('lang')
46         if click_id:
47             print(click_id)
48             click_hand = requests.post(url='https://dig.chouti.com/link/vote?linksId={}'.format(click_id),
49                                        headers=headers,
50                                        cookies=cookie_dict,
51                                        )

猜你喜欢

转载自www.cnblogs.com/wangyajian/p/9156242.html