02.UA身份标识

import requests
#UA伪装:将对应的ueser-agent封装到一个字典中
headers={
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0"
}
url="https://www.sogou.com/web"
#处理url携带的参数:封装到字典中
kw=input("enter an word:")
params={
'query':kw
}
#对指定的url发起的请求,对应的url是携带参数的,并且在请求过程中,处理参数
response=requests.get(url=url,params=params,headers=headers)

page_text=response.text

findName=kw+'.html'
with open(findName,'w',encoding='utf-8') as fp:
fp.write(page_text)
print("over!")




 

posted @ 2020-12-08 11:05  nan4457  阅读(124)  评论(0)    收藏  举报