我正在尝试使用 Splinter 浏览器库(带有 ChromeDriver)和 Pillow 库的组合从网页下载图像。我正在使用 Chrome 浏览器的实例登录网站并导航到带有图像的页面,然后使用该browser.find_by_tag()
方法定位图像。
然后我尝试使用Image.save()
Pillow 的方法,但它抛出了这个错误:
C:\Users\my.name\Documents\Development\Python-Scripts>my_script.py
Traceback (most recent call last):
File "C:\Users\my.name\Documents\Development\Python-Scripts\my_script.p
y", line 31, in <module>
my_function()
File "C:\Users\my.name\Documents\Development\Python-Scripts\my_script.p
y", line 19, in my_function
farmer_image = Image.save(farmer_image_brobj)
AttributeError: 'module' object has no attribute 'save'
我的代码:
from splinter import Browser
from PIL import Image
def my_function():
with Browser('chrome') as browser:
url = "http://www.blah/login.aspx"
url_two = "http://www.blah/ImagePageParent.aspx"
browser.visit(url)
browser.fill('un', 'blah')
browser.fill('pw', 'blah')
browser.find_by_name('btn').click()
browser.visit(url_two)
browser.find_link_by_partial_href('partial_href').click()
farmer_image_brobj = browser.find_by_tag('img')
farmer_image = Image.save(farmer_image_brobj)
browser.visit(url_two)
browser.quit()
my_function()