同样要通过requests 和 Beautifulsoup库来操作.
登录操作就比较好, 值得学习.
对于cookie 的授权是一个值得思考的问题.
下面有一些东西需要自己填.
1 import requests 2 from bs4 import BeautifulSoup 3 #当前cookies 未授权 4 response = requests.post( 5 url='https://dig.chouti.com/all/hot/recent/1', 6 headers={ 7 'User-Agent':'' 8 } 9 ) 10 cookie_dict = response.cookies.get_dict() 11 12 #此时cookies 已授权 13 r1 = requests.post( 14 url='https://dig.chouti.com/login', 15 data={ 16 'phone': '', 17 'password': '', 18 'oneMonth': '1' 19 }, 20 headers={ 21 'User-Agent':'' 22 }, 23 cookies=cookie_dict 24 ) 25 26 print(r1) 27 response.encoding = response.apparent_encoding 28 29 soup = BeautifulSoup(response.text, 'lxml') 30 31 div = soup.find(name='div', id='content-list') 32 33 item = div.find_all(attrs={'class':'item'}) 34 for it in item: 35 ans = it.find(attrs={'class':'part2'}) 36 id = ans.get("share-linkid") 37 #推荐 38 r1 = requests.post( 39 url='https://dig.chouti.com/link/vote?linksId=' + str(id), 40 headers={ 41 'User-Agent': '' 42 }, 43 cookies=cookie_dict 44 ) 45 #取消推荐 46 # r1 = requests.post( 47 # url='https://dig.chouti.com/vote/cancel/vote.do', 48 # data={ 49 # 'linksId':str(id) 50 # }, 51 # headers = { 52 # 'User-Agent': '' 53 # }, 54 # cookies=cookie_dict 55 # ) 56 57 58 print(r1.text)