python爬虫基础(requests、BeautifulSoup)

时间:2021-12-11 06:44:05

 python爬虫基础(requests、BeautifulSoup)

 

 • 抽屉网实现批量点赞

 

python爬虫基础(requests、BeautifulSoup)python爬虫基础(requests、BeautifulSoup)
 1 from  bs4 import BeautifulSoup
 2 import requests
 3 
 4 
 5 headers={
 6         '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',
 7     }
 8 
 9 
10 resoponse_1 = requests.get(url='https://dig.chouti.com/',
11                            headers=headers
12                            )
13 cookie_dict = resoponse_1.cookies.get_dict()
14 
15 resoponse_2 = requests.post(
16     url='https://dig.chouti.com/login',
17     data={
18         'phone':'8615733239039',
19         'password':'xxxxxx',
20         'oneMonth':'1',
21     },
22     headers=headers,
23     cookies=cookie_dict
24 )
25 for page in range(1,3):
26     html = requests.get(url='https://dig.chouti.com/all/hot/recent/{}'.format(page),headers=headers)
27     soup = BeautifulSoup(html.text,'html.parser')
28     divs = soup.find(name='div',id='content-list')
29     items = divs.find_all(attrs={'class':'item'})
30     for i in items:
31         click_id = i.find('img').get('lang')
32         if click_id:
33             print(click_id)
34             click_hand = requests.post(url='https://dig.chouti.com/link/vote?linksId={}'.format(click_id),
35                                        headers=headers,
36                                        cookies=cookie_dict,
37                                        )
View Code