Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python XPath查找只包含数字的所有链接?_Python_Regex_Xpath_Mechanize - Fatal编程技术网

Python XPath查找只包含数字的所有链接?

Python XPath查找只包含数字的所有链接?,python,regex,xpath,mechanize,Python,Regex,Xpath,Mechanize,我已经选择了一个页面中的元素,该页面包含我想要的页面链接。它们有点像。我想将正则表达式与xpath结合使用,这样我就可以获得所有类似的链接,其文本为\d+ 我知道这里有一个答案:但我无法理解 更具体地说,“请注意,您需要给出名称空间映射,以便它知道xpath表达式中的“re”前缀代表什么。” 以下是已清理页面中的代码:1 到目前为止,我的代码是: answer = browser.open(address) tree = lxml.html.parse(answer) numbers = tre

我已经选择了一个页面中的元素,该页面包含我想要的页面链接。它们有点像
。我想将正则表达式与xpath结合使用,这样我就可以获得所有类似的链接,其文本为
\d+

我知道这里有一个答案:但我无法理解

更具体地说,“请注意,您需要给出名称空间映射,以便它知道xpath表达式中的“re”前缀代表什么。”

以下是已清理页面中的代码:
1




到目前为止,我的代码是:

answer = browser.open(address)
tree = lxml.html.parse(answer)
numbers = tree.xpath("//div[contains(@class, 'pagination')]")[0]

此XPath表达式不需要RegExp:

//div[
   contains(
      concat(' ',@class,' '),
      ' pagination '
   )
]/a[
  floor()=.
]

此XPath表达式不需要RegExp:

//div[
   contains(
      concat(' ',@class,' '),
      ' pagination '
   )
]/a[
  floor()=.
]
不提供匹配regexp的方法

但是,您链接到的帖子中使用的扩展应该允许以下功能工作:

//div[contains(@class, 'pagination')]/a[re:match(text(), '^\d+$')]
不提供匹配regexp的方法

但是,您链接到的帖子中使用的扩展应该允许以下功能工作:

//div[contains(@class, 'pagination')]/a[re:match(text(), '^\d+$')]
您写道“XPath不提供匹配regexp的方法”。那是错误的。这是您编写的最后一个XPath规范“XPath不提供匹配regexp的方法”。那是错误的。这是最后一个XPath规范