美文网首页
2020-03-19 get的获取2

2020-03-19 get的获取2

作者: f5423d3134f0 | 来源:发表于2020-03-23 07:49 被阅读0次
# 导入需要的方法
from urllib.request import Request, urlopen
from urllib.parse import urlencode
from fake_useragent import UserAgent

# 创建需要编译的元素
args = {
    "ie": "utf-8",
    "wd": "尚学堂"
}
#编译并且格式化字符串
url = "https://www.baidu.com/s?{}".format(urlencode(args))
#创建随机表头
headers = {
    "User_Agent": UserAgent().random
}
#创建request对象
request = Request(url, headers=headers)
#创建resp对象
resp = urlopen(request)
#创建 read 对象
info = resp.read()
#输出 decode后的html格式
print(info.decode())

总结: 已经开始晕头转向,最后输出总是几行代码,查看代码无毛病,可能跟使用随机代码 有关系。睡觉

相关文章

网友评论

      本文标题:2020-03-19 get的获取2

      本文链接:https://www.haomeiwen.com/subject/mmzryhtx.html