urllib运用(2)

2021-04-02 17:26

阅读:740

标签:inpu   use   base   agent   fir   color   查询   write   mozilla   

# 使用parse对网址进行拼接操作
from urllib import request,parse
base_url = https://www.baidu.com/s?
wd = input(请输入查询信息>>)
query_msg = {
    wd:wd
}
msg = parse.urlencode(query_msg)
url = base_url+msg

header = {
    User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
}

req = request.Request(url=url,headers=header)
response = request.urlopen(req).read().decode(utf-8)

with open(teiba.html,w,encoding=utf-8)as files:
    files.write(response)

 

urllib运用(2)

标签:inpu   use   base   agent   fir   color   查询   write   mozilla   

原文地址:https://www.cnblogs.com/lizhihoublog/p/11206785.html


评论


亲,登录后才可以留言!