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)
  • 相关阅读:
    105.UDP通信实现广播
    104.tcp多线程读写实现群聊
    103.tcp通信实现远程控制
    102.tcp实现多线程连接与群聊
    101.自动注入
    100.dll调用
    99.遍历进程并直接写入内存
    98.TCP通信传输文件
    97.TCP通信
    96.udp通信
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/10180117.html
Copyright © 2011-2022 走看看