spider_使用request库进行get传参

"""
使用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))
posted @ 2019-06-05 10:38  猫有九命  阅读(300)  评论(0编辑  收藏  举报