Scrapy编写未知深度的XPath表达式(Scrapy writing XPath expression for unknown depth)
我有一个html文件,如:
<div id='author'> <div> <div> ... <a> John Doe </a>我不知道作者div下会有多少div。 它可能具有不同页面的不同深度。
那么这种xml的XPath表达式是什么?
顺便说一句,我试过:
//div[@id = "author"]/*/a/text()但这似乎只适用于作者div的孙子。
I have an html file which is like:
<div id='author'> <div> <div> ... <a> John Doe </a>I do not know how many div's would be under the author div. It may have different depth for different pages.
So what would be the XPath expression for this kind of xml?
By the way, I tried:
//div[@id = "author"]/*/a/text()but this only seems to work for grandchildren of the author div.
最满意答案
使用双斜杠在div元素内的任何位置找到一个id="author"元素:
//div[@id = "author"]//a/text()Use double slash to find an a element anywhere inside the div element with id="author":
//div[@id = "author"]//a/text()更多推荐
发布评论