# coding:utf-8 import urllib import urllib2 url = "http://wwww.baidu.com/s" headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"} keyword = raw_input("请输入需要查询的关键字: ") wd = {"wd" : keyword} wd = urllib.urlencode(wd) fullurl = url + "?" + wd #print fullurl request = urllib2.Request(fullurl, headers = headers) response = urllib2.urlopen(request) print response.read()