2017-12-21-selenium-simulation-chrome

layouttitledescriptionkeywordscategorytags
post
selenium模块模拟Chrome浏览器
selenium模块模拟Chrome浏览器
python, selenium
python
python
selenium

2017-12-21-selenium-simulation-chrome

  1. 参考资料1
  2. 参考资料2
  3. 下载Chrome浏览器driver brew install chromedriver
  4. crawlera神器 该工具主要是为了防止反爬 iP被封
  5. pip selenium

环境说明

# 1. selenium  : 3.8.0
# 2. Scrapy    : 1.4.0
# 3. lxml      : 3.8.0.0
# 4. libxml2   : 2.9.4
# 5. cssselect : 1.0.1
# 6. parsel    : 1.2.0
# 7. w3lib     : 1.18.0
# 8. Twisted   : 17.9.0
# 9. Python    : 2.7.14 (default, Sep 25 2017, 09:54:19) - [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
# 10. pyOpenSSL : 17.2.0 (OpenSSL 1.1.0f  25 May 2017)
# 11. Platform  : Darwin-17.2.0-x86_64-i386-64bit
from selenium import webdriver
from time import sleep

mobileEmulation = {
    "deviceMetrics": {
        "width": 320, 
        "height": 640, 
        "pixelRatio": 3.0 
    }, 
    "userAgent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)
# self.driver = webdriver.PhantomJS(executable_path=settings['JS_BIN'])
driver = webdriver.Chrome(executable_path='your chromedriver bin path',
                          chrome_options=options,
                          service_args=["--verbose", "--log-path=qc1.log"])
driver.get('http://m.dianping.com')

sleep(1000)
driver.close()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值