iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python第三方库undetected_chromedriver的使用
  • 257
分享到

Python第三方库undetected_chromedriver的使用

undetected_chromedriver使用undetected_chromedriver 2023-01-12 12:01:14 257人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

undetected_chromedriver是专门针对浏览器识别做出来的拓展 直接使用undetected_chromedriver第三方库 if __name__ == '__m

undetected_chromedriver是专门针对浏览器识别做出来的拓展

直接使用undetected_chromedriver第三方库

if __name__ == '__main__':

	from selenium import WEBdriver
	from selenium.webdriver.common.by import By
	from selenium.webdriver.support.ui import WebDriverWait
	from selenium.webdriver.support import expected_conditions
	import undetected_chromedriver.v2 as uc
	
	chrome_options = uc.ChromeOptions()
	chrome_options.add_argument("--disable-extensions")
	chrome_options.add_argument("--disable-popup-blocking")
	chrome_options.add_argument("--profile-directory=Default")
	chrome_options.add_argument("--ignore-certificate-errors")
	chrome_options.add_argument("--disable-plugins-discovery")
	chrome_options.add_argument("--incognito")
	chrome_options.add_argument('--no-first-run')
	chrome_options.add_argument('--no-service-autorun')
	chrome_options.add_argument('--no-default-browser-check')
	chrome_options.add_argument('--passWord-store=basic')
	chrome_options.add_argument('--no-sandbox')
	
	driver = uc.Chrome(options=chrome_options, executable_path='./driver/chromedriver')
	
	driver.delete_all_cookies()
	driver.get("https://accounts.Google.com/signin/v2/identifier?service=accountsettings&continue=Https%3A%2F%2Fmyaccount.google.com%3Futm_source%3Daccount-marketing-page%26utm_medium%3Dgo-to-account-button&flowName=GlifWebSignIn&flowEntry=ServiceLogin")
	
	driver.find_element_by_xpath('//input[@type="email"]').send_keys(email)
	input = WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="identifierNext"]')))
	input.click()
	
	WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')))
	driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)
	
	input = WebDriverWait(driver, 100).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="passwordNext"]/div/button')))
	input.click()
	time.sleep(5)
	
	cookies = driver.get_cookies()
	cookies_arr = []
	for c in cookies:
	    if c['domain'].endswith('.google.com'):
	        cookies_arr.append(f'{c["name"]}={c["value"]}')
	
	driver.close()
	return "; ".join(cookies_arr)

使用seleniumwire的undetected_chromedriver拓展,好处是可以直接获取到浏览器的请求记录

from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
import time
if __name__ == '__main__':
    options = {}
    chrome_options = ChromeOptions()
    chrome_options.add_argument("--disable-gpu")
    chrome_options.add_argument("--incognito")
    chrome_options.add_argument("--disable-dev-shm-usage")
    # chrome_options.add_argument("--headless")
    chrome_options.add_argument(f"--proxy-server=http://192.168.100.24:60021")
    chrome_options.add_argument("--disable-popup-blocking")
    chrome_options.add_argument("--profile-directory=Default")
    chrome_options.add_argument("--ignore-certificate-errors")
    chrome_options.add_argument("--disable-plugins-discovery")
    chrome_options.add_argument('--no-first-run')
    chrome_options.add_argument('--no-service-autorun')
    chrome_options.add_argument('--no-default-browser-check')
    chrome_options.add_argument('--password-store=basic')
    chrome_options.add_argument('--no-sandbox')
    browser = Chrome(seleniumwire_options=options, options=chrome_options,executable_path='C:\Program Files\Google\Chrome\Application\chromedriver.exe',version_main=101)

    browser.get('https://portal.thecourierguy.co.za/track?ref=TCG107468416T')
    time.sleep(15)
    print(browser.page_source)
    for request in browser.requests:
        if request.response:
            print(request.path)
            if 'shipments' in request.path:
            	print(request.response.body)
            #获取内容为乱码可尝试用以下方法解码
            #gzip.decompress(request.response.body).decode("utf-8")

其中version_main可以根据浏览器版本指定版本号

注意:

      使用seleniumwire.undetected_chromedriver有一个大坑

      输入executable_path不会生效,因为在webdriver的源码是单独引用的undetected_chromedriver

所以不会接收到传入的executable_path。

而在undetected_chromedriver源码中,如果没有传入path就会每次启动去官网重新下载一个新的驱动器,再编译成可执行的文存放在以下目录

解决办法:

      在webdriver的源码中指定executable_path

这个带有前缀id的chromedriver是有执行权限的可执行程序啦

(直接使用官网下载的可能会没有权限,可以先直接运行一次,去到对应目录下面找到一个就可以永久使用啦<其他的可以删除>)

总结

到此这篇关于python第三方库undetected_chromedriver使用的文章就介绍到这了,更多相关Python undetected_chromedriver使用内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Python第三方库undetected_chromedriver的使用

本文链接: https://www.lsjlt.com/news/177510.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python第三方库undetected_chromedriver的使用
    undetected_chromedriver是专门针对浏览器识别做出来的拓展 直接使用undetected_chromedriver第三方库 if __name__ == '__m...
    99+
    2023-01-12
    undetected_chromedriver使用 undetected_chromedriver
  • python第三方库pygame的使用详解
    作用:pygame一般用来做游戏 注意:1.在使用pygame提供的功能之前,需要调用init方法 2.在游戏结束前需要调用 quit 方法 pygame中的各个函数: 1.pyga...
    99+
    2024-04-02
  • Python 第三方库
    1 Python 第三方库Python语言与Perl,C和Java等语言有许多相似之处。但是,也存在一些差异。在本章中我们将来学习Python的基础语法,让你快速学会Python编程。Python 常用的标准库以及第三方库有哪些? req...
    99+
    2023-01-31
    第三方 Python
  • Python中第三方库Faker的使用详解
    目录背景介绍实战:模拟1w条数据写入ExcelPython库讲解1. 生成姓名2. 生成详细地址3. 生成所在省份4. 生成手机号5. 生成身份证号6. 生成出生年月7. 生成邮箱补...
    99+
    2024-04-02
  • python中第三方库pyecharts的使用详解
    与pyecharts有关的两个网站:官方网站:pyecharts - A Python Echarts Plotting Library built with love. ,画廊功能...
    99+
    2024-04-02
  • Python标准库及第三方库怎么使用
    本篇内容介绍了“Python标准库及第三方库怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、time模块1.time模块简介tim...
    99+
    2023-07-06
  • Python的第三方调试库​​​pysnooper​​使用示例
    目录一、背景二、示例 ​ ​pysnooper`​​三、方法一、背景 我们在进行代码调试时,通常使用两种方式。 print 输出调试的内容或者标识通过断点调试debug但是...
    99+
    2023-02-21
    Python调试神器PySnooper PySnooper使用示例 debug神器 PySnooper
  • python第三方库easydict的使用实例详解
    目录easydict是什么一、介绍二、安装三、使用easydict是什么 用一句话来说就是,让操作字典像是操作类成员方式一样方便。这个工具其实没有很多要说的,因为它太简单了,简单到网...
    99+
    2022-11-13
    python easydict使用 python第三方库easydict python easydict
  • Python的第三方调试库pysnooper​​如何使用
    本篇内容主要讲解“Python的第三方调试库pysnooper如何使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python的第三方调试库pysnooper如何使用”吧!一、背景我们在进行代...
    99+
    2023-07-05
  • 如何在python中使用paramiko第三方库
    这期内容当中小编将会给大家带来有关如何在python中使用paramiko第三方库,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。python是什么意思Python是一种跨平台的、具有解释性、编译性、互动性...
    99+
    2023-06-06
  • 使用Python第三方库生成二维码
    本文主要介绍两个可用于生成二维码的Python第三方库:MyQR和qrcode。 MyQR的使用: 安装: pip install MyQR 导入: from MyQR import myqr import os 生成二维码:...
    99+
    2023-01-30
    第三方 二维码 Python
  • Python第三方库gTTs/pyttsx3/speech怎么使用
    Python文字转语音(调研&成品函数)由于项目需要, 我需要将文字转换为语音, 那么第一步就要进行调研什么是语音合成技术语音合成(text to speech),简称TTS。是将文字转化为语音的一种技术,是让计算机模拟人类的嘴巴,...
    99+
    2023-05-14
    Python speech
  • Python第三方库paramiko S
    基于用户名和密码的sshclient方式登录:#!/usr/bin/env python #-*- coding=utf-8 -*- #说明:基于用户名和密码的sshclient方式登录 import paramiko try:     s...
    99+
    2023-01-31
    第三方 Python paramiko
  • python如何调用第三方库
    Python调用第三方库通常需要以下几个步骤:1. 安装第三方库:使用pip工具安装第三方库,比如`pip install requ...
    99+
    2023-10-11
    python
  • vscode怎么使用第三方库
    在VSCode中使用第三方库的步骤如下: 在项目文件夹下创建一个 package.json 文件,可以通过命令 npm init...
    99+
    2024-04-09
    vscode
  • pycharm怎么使用第三方库
    如何在 pycharm 中使用第三方库 在 PyCharm 中使用第三方库的步骤: 1. 安装库 在命令提示符或终端中使用 pip 命令:pip install 库名 在 PyCha...
    99+
    2024-04-18
    python pycharm
  • 我常用的几个第三方 Python 库
    作者:赖勇浩(http://blog.csdn.net/lanphaday) 今天公司停电,没上班。跑上来更新个博客,跟大家分享一下我常用的几个第三方 Python 库。Python 语言之所以能够如此流行,除了本身内置许多程序库来保障...
    99+
    2023-01-31
    几个 第三方 常用
  • Python中的第三方JSON库怎么用
    这篇文章主要介绍了Python中的第三方JSON库怎么用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中的第三方JSON库怎么用文章都会有所收获,下面我们一起来看看吧。orjson常用方法orjso...
    99+
    2023-07-06
  • Java第三方库JodaTime的具体使用
    目录1、使用JodaTime 2、获取DateTime实例 3、使用DateTime的方法 4、使用Property的 5、其他的静态方法 结语 Java8之前的时间库中存在一些设计...
    99+
    2024-04-02
  • python yagmail第三方库发送
    1.安装第三方库yagmail:   pip install yagmail 2.上代码 1 import yagmail 2 import os 3 4 5 def send_email(): 6 7 #链...
    99+
    2023-01-30
    第三方 python yagmail
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作