Extracting node values using XPath

后端 未结 3 1370
不知归路
不知归路 2021-01-24 18:42

There is a section of amazon.com from which I want to extract the data (node value only, not the link) for each item.

The value I\'m looking for is inside and <

3条回答
  •  一向
    一向 (楼主)
    2021-01-24 19:18

    The following expression should work:

    //*[@id='ref_1000']/li/a/span[@class='narrowValue']
    

    For better performance you could provide a direct path to the start of this expression, but the one provided is more flexible (given that you probably need this to work across multiple pages).

    Keep in mind, also, that your HTML parser might generate a different result tree than the one produced by Firebug (where I tested). Here's an even more flexible solution:

    //*[@id='ref_1000']//span[@class='narrowValue']
    

    Flexibility comes with potential performance (and accuracy) costs, but it's often the only choice when dealing with tag soup.

提交回复
热议问题