Capture and analyze webpage content using python curl and lxml

Source: Internet
Author: User

Curl is a powerful URL syntax client that supports DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, and other protocols.

Lxml is a very useful xml module in python and supports html processing. Although html is a subset of xml, some html webpages are not properly written. For example, if you write <option> but do not write </option>, in this case, an error is returned when you use an xml tool for analysis. However, html tools are generally compatible with these non-standard situations.

Using urljoin of urlparse can help you deal with relative path problems.

If your python lacks curl or lxml modules, you can go to pypi to find them.

= 8 === ht_doc.xpath (I urlparse. urljoin (base_url, I. get (lxml. etree. tostring (I, encoding =

 

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.