Using python to capture documents from the web,

Source: Internet
Author: User

Using python to capture documents from the web,

The example in this article describes how to capture documents from a URL of the Web using Python and share it with you for your reference. The specific method is analyzed as follows:

The instance code is as follows:

Import urllib doc = urllib. urlopen ("http://www.python.org "). read () print doc # print the web page def reporthook (* a): print a # Save the http://www.renren.com web page to renre.html, # Each read a block calls a word reporthook function urllib. urlretrieve ("http://www.renren.com", 'renren.html ', reporthook) # Save the http://www.renren.com web page to urllib in renre.html. urlretrieve ("http://www.renren.com", 'renren.html ')

The program running result is as follows:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> .................. ........ webpage content </body>  

Urllib. urlopen returns a class object.

I hope this article will help you with Python programming.




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.