首页 > 解决方案 > Python Selenium 图像抓取到文本

问题描述

我正在使用 selenium 从网站上将图像刮成文本,然后将它们放入 csv 文件中,http ://www.58food.com/company_a1245289688.html

不知道硒是否可以做到这一点?非常感谢!!

driver.find_element_by_xpath('//*[@class="contact-text"]/d1/img[1]')
driver.find_element_by_xpath('//*[@class="contact-text"]/d1/img[2]')
and then..?

标签: pythonimageselenium

解决方案


import urllib.request
import base64


imgsrc=driver.find_element_by_xpath('//*[@class="contact-text"]/d1/img[1]').get_attribute("src")

 local_filename, headers = urllib.request.urlretrieve(src)
 encoded_string = base64.b64encode(image_file.read())

检索src,然后使用urllib获取img,然后将其转换为base64


推荐阅读