urllib通过Get请求爬取KeyWords页面信息
程序员文章站
2022-05-03 23:48:09
...
import baseSpider
import urllib
# www.baidu.com/s?wd=python
keyword = input("请输入你要查询的关键词:")
wd = {"wd":keyword}
# 这里需要做urlencode,以保证浏览器能够识别所有的字符信息
wd = urllib.parse.urlencode(wd)
#print(wd)
url = "http://www.baidu.com/s?"
url += wd
# downloadPage函数是封装好的函数,这里不做解释
html = baseSpider.downloadPage(url)
with open("baiduSearch.html", "wb") as f:
f.write(html.encode('utf-8'))