python request 请求头_python爬虫请求头如何设置?

一、requests设置请求头:

import requests

url="http://www.targetweb.com"

headers={

'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',

'Cache-Control':'max-age=0',

'Connection':'keep-alive',

'Referer':'http://www.baidu.com/',

'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4882.400 QQBrowser/9.7.13059.400'}

res=requests.get(url,headers=headers)

#图片下载时要用到字节流,请求方式如下

#res=requests.get(url,stream=True,headers)

二、Selenium+Chrome请求头设置:

from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_argument('lang=zh_CN.

你可能感兴趣的:(python,request,请求头)