爬虫基础——示例:登陆抽屉并点赞

   方法一

import requests

### 访问 ###
r1 = requests.get(
    url="https://dig.chouti.com/",
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
)
r1_cookie = r1.cookies.get_dict()
print(r1_cookie)

### end ###

### 登陆 ###
post_dict = {
    'phone': '86xxxxx',
    'password': 'xxxxxx',
    'oneMonth': 1,
}
r2 = requests.post(
    url="https://dig.chouti.com/login",
    data=post_dict,
    headers= {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
    cookies=r1_cookie,
)

r2_cookie = r2.cookies.get_dict()
print(r2_cookie)
### end ##

### 点赞 ###
r3 = requests.post(
    url="https://dig.chouti.com/link/vote?linksId=20476281",
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
    cookies=r1_cookie
)

print(r3.text)

### end ###

   方法二

import requests


session = requests.Session()


### 访问 ###
r1 = session.get(
    url="https://dig.chouti.com/",
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
)


### end ###

### 登陆 ###
post_dict = {
    'phone': '86xxxxxx',
    'password': 'xxxx',
    'oneMonth': 1,
}
r2 = session.post(
    url="https://dig.chouti.com/login",
    data=post_dict,
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
)

### end ##

### 点赞 ###
r3 = session.post(
    url="https://dig.chouti.com/link/vote?linksId=20487636",
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}'
    },
)

print(r3.text)

猜你喜欢

转载自www.cnblogs.com/gaosy-math/p/9389341.html