Python Crawler Tutorial -09-error module

Source: Internet
Author: User

Python Crawler Tutorial -09-error module

Today's protagonist is the error, crawl, it is easy to appear wrong, so we have to do in the code, common mistakes in the place, about Urllib.error

Urlerror
    • Reasons for Urlerror production:
      • 1. No network connection
      • 2. Server Connection failure
      • 3. The specified server could not be found
      • 4.URLError is a subclass of OSError
      • Case V9 File: https://xpwi.github.io/py/py%E7%88%AC%E8%99%AB/py09error.py
# 案例v9# URLError的使用from urllib import  request,errorif __name__ == ‘__main__‘:    url = "http://www.baiiiiiiiiiiidu.com/"    try:        req = request.Request(url)        rsp = request.urlopen(req)        html = rsp.read().decode()        print(html)    except error.URLError as e:        print("URLError:{0}".format(e.reason))        print("URLError:{0}".format(e))    except Exception as e:        print(e)

Httperror
    • 1. is a subclass of Urlerror
The difference between Urlerror and Httperror:
    • Httperror is a return code error for the corresponding HTTP request, and if the return error code is more than 400, the httperror is raised
    • Urlerror corresponds to a network problem, including URL problems
      -This note does not allow any person or organization to reprint

Python Crawler Tutorial -09-error module

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.