python - 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..?
解决方案
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
推荐阅读
- google-sheets - 谷歌表 - sumif 值与文本
- ruby-on-rails-5 - ruby on rails 5.2 --“form for”无法更新
- ruby-on-rails - 未捕获的参考错误 railsadmin 未定义 turbo 链接问题?
- asp.net-mvc - 处理异常字符串的最佳方法未被识别为有效的日期时间
- python - Python nfc 模块
- jquery - 更改 Ajax 获取带有输入的 JSON 密钥
- javascript - 有效的 XML 数据,但在 XMLHttpRequest 响应的 responseXML 属性中为 null
- linux - 清除 Linux 终端仿真器中的最后两个(及更多)打印行
- angular - PrimeNG 下拉列表 - 嵌套的 ng 模板
- autohotkey - AutoHotKey 太快热键按下崩溃脚本