首页 > 代码库 > Python实现百度搜索并保存到本地示例,Python实现百度搜索

Python实现百度搜索并保存到本地示例,Python实现百度搜索

实现百度搜索并保存到本地

User_Agent = ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36‘ import urllib2 import urllib url = "https://www.baidu.com/s?wd=" key = "博客园" key_code = urllib.quote(key) url_all = url + key_code req = urllib2.Request(url_all) req.add_header(‘User-Agent‘,AA) data = http://www.mamicode.com/urllib2.urlopen(req).read()"F:/11/11.html","wb") fh.write(data) fh.close()

  

Python实现百度搜索并保存到本地示例,Python实现百度搜索