我有这个脚本打开一个浏览器页面,其中包含我想从此页面下载所有图像的所需网页,如何在此脚本下执行此操作:
from selenium import webdriver
import urllib
class ChromefoxTest:
def __init__(self,url):
self.url=url
def chromeTest(self):
self.driver=webdriver.Chrome()
self.driver.get(self.url)
self.r=self.driver.find_element_by_tag_name('img')
self.uri=self.r.get_attribute("src")
self.g=urllib.urlopen(self.uri)
if __name__=='__main__':
FT=ChromefoxTest("http://www.google.com")
FT.chromeTest()
答案 0 :(得分:1)
from selenium import webdriver
import urllib
class ChromefoxTest:
def __init__(self,url):
self.url=url
self.uri = []
self.folder = '/home/palladin/imgs'
def chromeTest(self):
self.driver=webdriver.Chrome()
self.driver.get(self.url)
self.r=self.driver.find_elements_by_tag_name('img')
for v in self.r:
src = v.get_attribute("src")
self.uri.append(src)
pos = len(src) - src[::-1].index('/')
print src[pos:]
self.g=urllib.urlretrieve(src, "/".join([self.folder, src[pos:]]))
if __name__=='__main__':
FT=ChromefoxTest("http://www.google.com")
FT.chromeTest()