请选择 进入手机版 | 继续访问电脑版

平方X

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2198|回复: 0

[2508]selenium+PhantomJS

[复制链接]

414

主题

709

帖子

3600

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3600
QQ
发表于 2018-1-16 14:50:18 | 显示全部楼层 |阅读模式
[md]
[Darkeril.《python爬虫的最佳实践(五)--selenium+PhantomJS的简单使用》](https://www.jianshu.com/p/520749be7377)

[Selenium](http://www.seleniumhq.org/)  
[PhantomJS](https://github.com/ariya/phantomjs)  
下载后配置环境变量,可以用命令行打开,但是还是运行不了。  
找到
> 第二步需要把phantomjs.exe拷贝放到python的安装目录下,才可以启动phantomjs。

# 指定 Chrome 的位置
chromedrive 会查找 chrome ,没找到报
cannot find Chrome binary
路径应该在 C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe
但是因为我手动修改了安装路径,导致找不到。

一开始我想在查找路径处添加快捷方式,失败(因为快捷方式带扩展名)
又想生成一个 exe 放那,估计也不行,无法建立连接。

看参数可以传
chrome_options

只传一个带 binary 的字典不行,需要别的参数。
看到默认处理是
selenium.webdriver.chrome.webdriver.WebDriver#create_options
于是直接
```
from selenium.webdriver.chrome.options import Options as ChromeOptions

        chrome_options = ChromeOptions()
        # 见类中的方法
        chrome_options.binary_location = r'D:\software\browser\Chrome\Application\chrome.exe'
        driver = webdriver.Chrome(chrome_options=chrome_options)
```
成功。[/md]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|平方X ( 冀ICP备14018164号 )

GMT+8, 2024-3-29 13:01 , Processed in 0.128563 second(s), 21 queries .

技术支持:Powered by Discuz!X3.4  © 2001-2013 Comsenz Inc.

版权所有:Copyright © 2014-2018 平方X www.pingfangx.com All rights reserved.

快速回复 返回顶部 返回列表