spider_使用request库进行get传参

2023-03-09,,

"""
使用requests库 在这里爬取百度搜索的端午节页面(使用request库进行get传参

"""
import requests
import chardet

url = "https://www.baidu.com/s?"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0"}

# 定义参数字典
paramsDict={"wd":"端午节"}
# 返回一个字节数组
bytesHtml= requests.get(url,params=paramsDict,headers=headers).content
print(bytesHtml)
print(type(bytesHtml))
# 判断网页编码,返回一个字典
resEncode=chardet.detect(bytesHtml)
#进行指定编码解码 获得的是一个字符串网页页面
html=bytesHtml.decode(resEncode["encoding"])
print(html)
print(type(html))

spider_使用request库进行get传参的相关教程结束。

《spider_使用request库进行get传参.doc》

下载本文的Word格式文档,以方便收藏与打印。