get请求是常用的请求之一,相对于post请求简单些,对于传参数的get请求有的还是有难度的,和post请求一样,必须知道每个字段的含义,这样拿到的响应才是正确的,也是我们想要的。
import requests
headers = {
“User-Agent”: “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36”,
}
url = “https://www.baidu.com/s?wd=%E8%82%A1%E7%A5%A8” # 等价下面的
response = requests.get(url, headers=headers).text
print(response)
import requests
headers={
“User-Agent”: “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36”,
}
url = ‘https://www.baidu.com/s’
params = {“wd”: “股票”}
response = requests.get(url=url, params=params, headers=headers).text
print(response)