Python uses get to search and save the first page of search results in Baidu
Author: Vpoet
Date: About in the summer
Note: Random copy, do not care about my feelings
#coding: Utf-8import urllibimport urllib2import Re "" "Use get to query This example on Baidu search engine shows how to generate a get string and make a request." "" If __name__== "__main__": url = "http://www.baidu.com/s" search = [(' W ', ' QQ ')] getString = URL + "?" + Urllib. UrlEncode (search) req = Urllib2. Request (getString) fd = Urllib2.urlopen (req) baiduresponse= "" While 1: data= fd.read (1024x768) if Not Len (data): break baiduresponse+=data fobj=open ("baidu.html", ' W ') fobj.write ( Baiduresponse) Fobj.close ()
Search QQ saved pages are:
Open to see:
and Baidu Search QQ results comparison:
Yes, it's the same. The page we saved doesn't have a picture because the HTML structure of the page we saved is not downloading the image link from the server, okay?
Python uses get to search and save the first page of search results in Baidu