我试图从这个输入链接描述中提取所有那些类名称适合正则表达式模式frag-0-0,frag-1-0等的标签
我正在尝试以下代码
driver = webdriver.PhantomJS()
for frg in frgs:
driver.get(URL + frg[1:])
frags=driver.find_elements_by_xpath("//*[starts-with(@id, 'frag-') and ends-with(@id, '-0')]")
for frag in frags:
for tag in frag.find_elements_by_css_selector('[class^=fragmark]'):
lst.append([tag.get_attribute('class'), tag.text])
driver.quit()
Run Code Online (Sandbox Code Playgroud)
这是我的追溯:
回溯(最近通话最后一个):文件"/home/ubuntu/workspace/vroniplag/vroni.py",线路116,在OP( 'AAF')文件"/home/ubuntu/workspace/vroniplag/vroni.py"线101,在运算plags = getplags(CD)文件"/home/ubuntu/workspace/vroniplag/vroni.py",线92,在getplags断支= driver.find_elements_by_xpath("// [开始-与(@id,' frag-')和ends-with(@ id,' - 0')]")文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",第305行在find_elements_by_xpath返回self.find_elements(由= By.XPATH,值= xpath的)文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",线路778,在find_elements '值':值})[ '值']文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",线路236,在执行self.error_handler. check_response(响应)文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",线192,在check_response加注exception_class(消息,屏幕,堆栈跟踪)硒.common.exceptions.InvalidSelectorException:消息:错误消息=>'无法找到带有xpath表达式的元素// [starts-with(@ id,'frag-')和ends-with(@id,' - 0') ]由于以下错误:错误:INVALID_EXPRESSION_ERR:由Request => {"headers"引起的DOM XPath异常51:{"接受":"application/json","Accept-Encoding":"identity","Connection" : "关闭", "内容长度": "139", "内容类型": "应用/ JSON;字符集= UTF-8", "主机": "127.0.0.1:45340","User-Agent" :"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using \":\"xpath \",\"sessionId \": \"0dbc6ad0-4352-11e6-8cb8-4faebd646180 \",\"value \":\"//*[开头 - (@id,'frag-')和结尾(@id,' - 0' )]\"}", "URL": "/元件", "urlParsed":{ "锚": …
我已经使用了结束函数作为 (By.xpath("//input[ends-with(@id,'_PHONE$']"));
但它没有用
嗨,我尝试获取包含href = / p / {random} /?tagged = see的所有元素,请参阅此处。
//div[preceding::h2[text()='Most recent']]/div/div/a[@href='/p/*/?tagged=see']
Run Code Online (Sandbox Code Playgroud)
我该如何解决此代码,必须将“ *”替换为其他内容?
我正在使用xmlstarletchangeSet从liquibase XML 变更日志中提取viewName以“v”结尾的节点。
然而,xmlstarlet 抱怨ends-withXPATH 函数不存在:
$ xmlstarlet sel -N x="http://www.liquibase.org/xml/ns/dbchangelog" -t -m \
"/x:databaseChangeLog/x:changeSet[x:createView[ends-with(@viewName, 'v')]]" \
-c . public.db.changelog.xml
xmlXPathCompOpEval: function ends-with not found
Unregistered function
Stack usage errror
xmlXPathCompiledEval: 3 objects left on the stack.
runtime error: element for-each
Failed to evaluate the 'select' expression.
None of the XPaths matched; to match a node in the default namespace
use '_' as the prefix (see section 5.1 in the manual).
For …Run Code Online (Sandbox Code Playgroud)