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

传单:

我想Python中使用PhantomJS我用谷歌搜索了这个问题,但是找不到合适的解决方案。

我发现os.popen()可能是一个不错的选择。但是我无法通过一些争论。

使用subprocess.Popen()可能是目前合适的解决方案。我想知道是否有更好的解决方案。

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

派克勒:

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

  1. 安装NodeJS
  2. 使用Node的包管理器安装phantomjs: npm -g install phantomjs-prebuilt
  3. 安装硒(如果使用virtualenv,请在其中)

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

from selenium import webdriver

driver = webdriver.PhantomJS() # or add to your PATH
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = 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')

参考文献:

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

有没有办法在querySelector中使用*?

有没有办法在watchOS中使用`useProtocolCachePolicy`?

有没有办法在gnuplot中使用通配符?

有没有办法在BottomSheetDialogFragment 中使用AlertDialog?

有没有办法在Firestore中使用GeoFire?

有没有办法在GLSL中使用联合?

有没有办法在JavaScript中使用C ++?

有没有办法在PostgreSQL中使用qualify

有没有办法在React中使用Wavify?

有没有办法在 Python 的函数中使用可选参数?

有没有办法在 Python 的函数中使用可选参数?

有没有办法在python中使用点运算符传递参数?

有没有办法在React Native应用程序中使用我的Python代码?

有没有办法在 python 中使用 sns.barplot 显示不同的颜色?

有没有办法在python中使用os.system打印文本?

有没有办法在Windows中使用python设置文件的详细信息?

有没有办法在Python3.8中使用rgb颜色?

有没有办法在Python的PySimpleGUI中使用其键获取输入?

有没有办法在python中使用函数属性

有没有办法用python在opencv中使用hdmi输入?

在python中使用.apply时有没有办法使用(如果数字在范围内)?

有没有办法使用python在Pandas DataFrame中使用行索引范围选择列的特定部分

有没有办法在 Spring 中使用带有延迟事件的 ApplicationEventPublisher?

有没有办法在Berkshelf中使用私有git仓库

有没有办法找到交流程序中使用的所有功能?

有没有办法查看演示文稿演示中使用的所有形状?

在.ui文件中描述函数时,有没有办法在python代码中使用retreanslateUi?

有没有办法提高在Windows下的Fortran中使用数组的速度,例如Python numpy?

有没有办法在Blender中使用python脚本复制/粘贴动作关键帧?