用selenium基本知识和流程

- selenium模块在爬虫中的使用
    - 概念:是一个基于浏览器自动化的模块。
    - 爬虫之间的关联:
        - 便捷的捕获到动态加载到的数据。(可见即可得)
        - 实现模拟登陆
    - 环境安装:pip install selenium
    - 基本使用:
        - 准备好某一款浏览器的驱动程序:http://chromedriver.storage.googleapis.com/index.html
            - 版本的映射关系:https://blog.youkuaiyun.com/huilan_same/article/details/51896672
        - 实例化某一款浏览器对象
    - 动作链:
        - 一系列连续的动作
        - 在实现标签定位时,如果发现定位的标签是存在于iframe标签之中的,则在定位时必须执行一个
        固定的操作:bro.switch_to.frame('id')
    - 无头浏览器的操作:无可视化界面的浏览器
        - PhantomJs:停止更新
        - 谷歌无头浏览器
    - 让selenium规避检测(先用window.navigator.webdriver判断,如果返回true,则需要规避检测)

先记录一下selenium的部分操作

#使用谷歌无头浏览器
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

driver = webdriver.Chrome(r'chromedriver.exe',chrome_options=chrome_options)
driver.get('https://www.cnblogs.com/')
print(driver.page_source)

#如何规避selenium被检测
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from time import sleep

option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])

driver = webdriver.Chrome(r'chromedriver.exe',options=option)
driver.get('https://www.taobao.com/')


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值