Python uses get to search and save the first page of search results in Baidu

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.