【发布时间】:2021-12-31 23:55:14
【问题描述】:
我正在尝试使用 xpath 表达式在我的网页中下载图像
部分代码
with open('stiker.png', 'wb') as file:
file.write(driver.find_element(By.XPATH,'//div[@class "_3IfUe"]/img[crossorigin = "anonymous"]').screenshot_as_png)
我正在尝试下载的部分页面源代码:
<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>
错误
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class "_3IfUe"]/img[@crossorigin = "anonymous"]' is not a valid XPath expression.
【问题讨论】:
-
我认为您需要在
@class和"_3IfUe"之间使用等号