python requests使用token进行爬虫

获取token
登录网页,按F12,找到application tab,查找cookie
python requests使用token进行爬虫_第1张图片

找到usertoken即可
然后就可以使用token了

from dataBase import Dbsession
from table import kenny
import requests
from requests.auth import HTTPBasicAuth
from pyquery import PyQuery as pq
def get():
    session=requests.Session()
    cookies={'UserContextToken':'fffffffffff'}
    for i in range(0,1,1):
        count = 47762729 + i
        url=f'https:fffffffff&id={count}'
        print(count)
        responsetext=session.get(url,cookies=cookies,timeout=20).text

        print(responsetext)
get()

使用token

import requests
response = requests.get(
... 'https://website.com/id', headers={'Authorization': 'access_token myToken'})

你可能感兴趣的:(Python)