Python 使用selenium提取图像时获取“无”
这是Html代码Python 使用selenium提取图像时获取“无”,python,selenium-webdriver,Python,Selenium Webdriver,这是Html代码 <div class="image-frame"><img alt="Figure 2, CT - noncontrast" data-action="zoom" class="" ng-click="zoomClick($event)" role="button" tabindex="0" ng-src="
<div class="image-frame"><img alt="Figure 2, CT - noncontrast" data-action="zoom" class="" ng-click="zoomClick($event)" role="button" tabindex="0" ng-src="/images/full/synpic100378.jpg" src="/images/full/synpic100378.jpg"> </div>
当该行应返回图像时,它将返回none
#insert image into data frame
**img =driver.find_element_by_class_name("image-frame").get_attribute("src")**
问题是您的
find\u element\u by\u class\u name()
返回的是
标记,而不是属性,因此它不返回任何内容
您可能希望尝试通过find\u element\u by\u css\u selector()
或find\u element\u by\u xpath()
来查找img标记。示例中的类名是否不同?请提供一个。这行在应该返回图像时返回none为什么?在您共享的HTML中,带有class
image frame
的元素似乎没有src
属性。谢谢!我最终使用了按xpath查找元素,这满足了我的需要。
#insert image into data frame
**img =driver.find_element_by_class_name("image-frame").get_attribute("src")**