zoukankan      html  css  js  c++  java
  • 自动抽屉 + 点赞 + 取消赞

    同样要通过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)
  • 相关阅读:
    计算机网络第五版答案 谢希仁
    AJAX代码示例(不使用AJAX控件)
    软件工程期末资料
    各类编程语言视频教程(300G)
    AJAX无刷新分页练习
    C#使用IrisSkin2.dll美化WinForm程序界面
    asp.net判断浏览器版本代码
    C#中国身份证验证
    在IIS中使用SSL配置HTTPS网站(转)
    silverLight导出报表
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/10180117.html
Copyright © 2011-2022 走看看