admin管理员组

文章数量:1614147

首先说明下这样做的好处:就是你不用验证登陆状态,可以先登陆,再爬虫

1.先打开windows cmd 进入chrome安装目录,一般在C:\Program Files (x86)\Google\Chrome\Application下,然后运行

chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"

就打开了一个chrome浏览器,后面就是操作这个浏览器了,你可以先登陆,然后cookie,token什么的都有了

2.代码实现

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
driver.get('https://me.csdn/ywah6666')

chrome_driver 这个路径要根据 自己的安装路径来,注意这里chromedriver.exe 要去下载一个,给出淘宝的镜像吧,国外的要翻墙;还有端口要一致,可以随便定义未使用的端口

https://chromedriver.storage.googleapis/index.html 

IE:

http://selenium-release.storage.googleapis/index.html

本文标签: 浏览器seleniumchrome