XPath for Python network data collection

Source: Internet
Author: User
Tags xpath

This article explains how to use XPath in scrapy to get the various values you want

Using watercress as an example

Https://book.douban.com/tag/%E6%BC%AB%E7%94%BB?start=20&type=T

You can verify that your XPath is correct in conjunction with the Plugin XPath helper in Chrome.

Here I want to get the title in the href and a tag under the a tag, use the Extract_first () in the red box in the picture, notice the syntax of the XPath here, "." In front of it, otherwise the query will start from the document root node instead of the current node .

If you want to get the text value within the tag, use/text () to

XPath for Python network data collection

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.