[英]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.