【发布时间】:2014-07-22 12:35:53
【问题描述】:
我使用了question 的第一个答案以使其适应我的需要:自动将给定 URL 的图片保存在我的笔记本电脑上。
我的问题是如何获取网页上存在的每个图像的 URI 以正确完成我的代码:
import selenium
class TestFirefox:
def testFirefox(self):
self.driver=webdriver.Firefox()
# There are 2 pictures on google.com, I want to download them
self.driver.get("http://www.google.com")
self.l=[] # List to store URI to my images
self.r=self.driver.find_element_by_tag_name('img')
# I did print(self.r) but it does not reflect the URI of
# the image: which is what I want.
# What can I do to retrieve the URIs and run this:
self.l.append(self.image_uri)
for uri_to_img in self.l:
self.driver.get(uri_to_img)
# I want to download the images, but I am not sure
# if this is the good way to proceed since my list's content
# may not be correct for the moment
self.driver.save_screenshot(uri_to_image)
driver.close()
if __name__=='__main__':
TF=TestFirefox()
TF.testFirefox()
【问题讨论】:
标签: firefox selenium python-3.x selenium-webdriver