Python3 Crawling Web pages

Source: Internet
Author: User

Crawler python3 Crawl Web page resource mode (1. The simplest:
    1. Import' http://www.baidu.com/'print2. Via Request
      1. Import' http://www.baidu.com 'print1.import urllib.request the difference between the ' wd ' python 'opt-webpage 'on ' ie ' GBK 'get and POST requests is that post requests usually have "side effects"   ' Mozilla/4.0 (compatible; MSIE 5.5; Windows NT) 'user-agent '
        Import Urllib.requestFrom Urllib.error import Urlerror, httperrorreq=urllib.request.request (' http://www.baidu.com ') Try: Urllib.request.urlopen (req) except Urlerror as E:print (E.reason) httperror
         1.Openers:2.Handles:  Import Urllib.requestPassword_mgr=urllib.request.httppasswordmgrwithdefaultrealm () top_level_url= "http://example.com/foo/" Password_ Mgr.add_password (None,top_level_url, ' why ', ' 1223 ') Handler=urllib.request.httpbasicauthhandler (password_mgr) Opener=urllib.request.build_opener (handler) a_url= ' http://www.baidu.com/' Opener.open (a_url) Urllib.request.install_opener (opener)The latter contains the port number.

Python3 Crawling Web pages

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.