简体   繁体   English

不是有效的 XPath 表达式

[英]Is not a valid XPath expression

I am trying to dowload a image in my web page with the xpath expression我正在尝试使用 xpath 表达式在我的 web 页面中下载图像

Part of code部分代码

    with open('stiker.png', 'wb') as file:
            file.write(driver.find_element(By.XPATH,'//div[@class "_3IfUe"]/img[crossorigin = "anonymous"]').screenshot_as_png)

Part of page source i'm trying to dowload:我正在尝试下载的部分页面源代码:

   <div class="_3IfUe">
       <img crossorigin="anonymous" src="blob:https://web.whatsapp.com/9a74a410-721b-4e8e-80f0-42d18288f480" 
       alt="" draggable="true" class="gndfcl4n p357zi0d ppled2lx ac2vgrno gfz4du6o r7fjleex g0rxnol2 ln8gz9je b9fczbqn i0jNr" style="visibility: visible;">
   </div>

Error错误

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class "_3IfUe"]/img[@crossorigin = "anonymous"]' is not a valid XPath expression.

As @John Gordon pointed out in his comment, you are missing a = between the @class and the value "_3IfUe" that you are trying to compare.正如@John Gordon在他的评论中指出的那样,您在@class和您要比较的值"_3IfUe"之间缺少一个=

After fixing that, you need an @ before the crossorigin attribute name.修复该问题后,您需要在crossorigin属性名称之前添加一个@ Otherwise, it thinks you are looking for an element with that name.否则,它认为您正在寻找具有该名称的元素。

It should be:它应该是:

//div[@class = "_3IfUe"]/img[@crossorigin = "anonymous"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有效的XPath表达式 - Valid XPath expression 不是有效的 XPath 表达式 - Not a valid XPath expression python selenium 说 xpath 表达式无效 - python selenium says xpath expression is not valid 错误:Xpath 不是有效的表达式 Selenium Python - Error: Xpath is not a valid expression Selenium Python 不是有效的 xpath 表达式 driver.find_element_by_xpath - not a valid xpath expression driver.find_element_by_xpath XPath 错误:[contains(text()=&quot;something&quot;)]&#39; 不是有效的 XPath 表达式 - XPath error: [contains(text()="something")]' is not a valid XPath expression selenium - 无法在&#39;Document&#39;上执行&#39;evaluate&#39;:字符串不是有效的XPath表达式 - selenium - Failed to execute 'evaluate' on 'Document': The string is not a valid XPath expression 不是一个有效的 XPath 表达式试图使用 div aria label 包含 - Not a valid XPath expression trying to use div aria label contains 在我的字符串中得到“导致字符串不是有效的 XPath 表达式 - inside my string got " result in The string is not a valid XPath expression 语法错误:无法在“文档”上执行“评估”:字符串 &#39;//img[contains(&#39;1236548597&#39;)]&#39; 不是有效的 XPath 表达式 - SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//img[contains('1236548597')]' is not a valid XPath expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM