有没有办法在Python中使用PhantomJS?

有没有办法在Python中使用PhantomJS?,第1张

有没有办法在Python中使用PhantomJS?

在python中使用PhantomJS的最简单方法是通过Selenium。最简单的安装方法是

  • 安装NodeJS
  • 使用Node的包管理器安装
    phantomjs: npm -g install phantomjs-prebuilt
  • 安装硒(在你的virtualenv中,如果正在使用)

安装后,你可以简单地使用phantom:

from selenium import webdriverdriver = webdriver.PhantomJS() # or add to your PATHdriver.set_window_size(1024, 768) # optionaldriver.get('https://google.com/')driver.save_screenshot('screen.png') # save a screenshot to disksbtn = driver.find_element_by_css_selector('button.gbqfba')sbtn.click()

如果你的系统路径环境变量设置不正确,则需要将确切路径指定为的参数webdriver.PhantomJS()。替换为:

driver = webdriver.PhantomJS() # or add to your PATH

…具有以下内容:

driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4942884.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存