【问题标题】:Harvest JS generated Image URI using SeleniumJSHarvest JS 使用 SeleniumJS 生成的图像 URI
【发布时间】:2015-07-28 20:37:58
【问题描述】:

我一直在尝试编写一个 python 脚本来让我从 whatsapp 网络上获取二维码。我使用 selenium,但似乎无法编写。

QR 图像是由 javascript live(因此是 selenium)生成的 PNG,其中它被转换为 Base64 中的 PNG 并由浏览器转换为图像。

到目前为止我的代码是这样做的:

import base64
from selenium import webdriver

url = "https://web.whatsapp.com"
init_search = "<img style=\"display: block;\" src=\"data:image/png;base64,"
term_search = "\"></div>"

browser = webdriver.Firefox()
browser.get(url)
html_source = browser.page_source

start = html_source.find(init_search)
end = html_source[start:].find(term_search)

raw_png = html_source[start+len(init_search):end]

print html_source[start:end]
print base64.b64decode(raw_png)

browser.close()

但它并不是很稳定。如何做到这一点,如果可能,无需实际打开浏览器?

【问题讨论】:

    标签: javascript python selenium base64 png


    【解决方案1】:

    好吧,为了不打开浏览器,你可以试试像 Phantom.js 这样的无头网络浏览器,它可以在你的终端上运行。

    http://phantomjs.org/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多