chromedriver禁用图片,禁用js,切换UA
selenium 模拟chrome浏览器,此时就是一个真实的浏览器,一个浏览器该加载的该渲染的它都加载都渲染,所以爬取网页的速度很慢。如果可以不加载图片等操作,网页加载速度就会快不少,代码中列出了了禁用图片,禁用JS,切换UA的方法。
 
   
 
from selenium import webdriver
 
from fake_useragent import UserAgent
 
   
 
ua = UserAgent().random
 
print(ua)
 
chrome_options = webdriver.ChromeOptions()
 
prefs = {
 
'profile.default_content_setting_values': {
 
# 也可以这样写,两种都正确
 
# 'profile.default_content_settings': {
 
'images': 2, # 不加载图片
 
'javascript': 2, # 不加载JS
 
"User-Agent": ua, # 更换UA
 
}
 
}
 
chrome_options.add_experimental_option("prefs", prefs)
 
browser = webdriver.Chrome(executable_path="C:/codeapp/seleniumDriver/chrome/chromedriver.exe", chrome_options=chrome_options)
 
#这个网页可以显示浏览器的信息,这样我们就可以看到我们的UA信息,
 
url = "https://httpbin.org/get?show_env=1"
 
browser.get(url)

python网页爬虫开发之六-Selenium使用的更多相关文章

  1. python网页爬虫开发之一

    1.beautifulsoap4 和 scrapy解析和下载网页的代码区别 bs可以离线解释html文件,但是获取html文件是由用户的其他行为的定义的,比如urllib或者request : 而sc ...

  2. python网页爬虫开发之三

    1.抓取目录页后用lxml进行页面解析,获取抓取列表 python3.6 urlparse模块变为urllib.parse 2.Python中有一个专门生成各类假数据的库:Faker 3.python ...

  3. python网页爬虫开发之七-多线程爬虫示例01

    from urllib.request import quote import urllib.request from bs4 import BeautifulSoup import re impor ...

  4. python网页爬虫开发之五-反爬

    1.头信息检查是否频繁相同 随机产生一个headers, #user_agent 集合 user_agent_list = [  'Mozilla/5.0 (Windows NT 6.1; WOW64 ...

  5. python网页爬虫开发之四-串行爬虫代码示例

    实现功能:代理.限速.深度.反爬 import re import queue import urllib.parse import urllib.robotparser import time fr ...

  6. Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)

    原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...

  7. 【Python】Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱

    本文转载自:https://www.cnblogs.com/colipso/p/4284510.html 好文 mark http://www.52nlp.cn/python-%E7%BD%91%E9 ...

  8. Python分布式爬虫开发搜索引擎 Scrapy实战视频教程

    点击了解更多Python课程>>> Python分布式爬虫开发搜索引擎 Scrapy实战视频教程 课程目录 |--第01集 教程推介 98.23MB |--第02集 windows下 ...

  9. Python网页爬虫(一)

    很多时候我们想要获得网站的数据,但是网站并没有提供相应的API调用,这时候应该怎么办呢?还有的时候我们需要模拟人的一些行为,例如点击网页上的按钮等,又有什么好的解决方法吗?这些正是python和网页爬 ...

随机推荐

  1. NOIP竞赛须知

    初赛报名 1.凡初.高中阶段的选手和同等年龄段中等专业学校的在校生均可以报名参加NOIP赛事. 2.选手以学籍学校为单位在指导教师处报名,由指导教师汇总本校学校报名情况并提交给NOI省特派员,由省特派 ...

  2. librdkafka安装和php扩展php-rdkafka安装

    1.安装librdkafka mac下   brew install librdkafka linux下 git clone https://github.com/edenhill/librdkafk ...

  3. js计算时间差

    <!doctype html> <html lang="en"> <head> <meta http-equiv="Conten ...

  4. SQL-45 将titles_test表名修改为titles_2017。

    题目描述 将titles_test表名修改为titles_2017.CREATE TABLE IF NOT EXISTS titles_test (id int(11) not null primar ...

  5. Java log4j

    <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging& ...

  6. java中的Iterator和ListIterator的区别

    (一)iterator迭代器 Collection的iterator方法返回一个实现了一个Iterator接口的对象 Iterator接口中包含三个方法: 1)E next() 2)boolean h ...

  7. VirtualBox安装CENTOS7.3常见问题

    1 DHCP 问题无法上网解决 :sudo dhclient 2 安装宝塔面板:yum install -y wget && wget -O install.sh http://dow ...

  8. VS Code 工具配置和格式化

    { "onSave": true, "javascript": { "indent_size": 2, "indent_char& ...

  9. nf_conntrack

    How to Fix Nf_conntrack Table Full Dropping Packet Linux CentOS PacketLoss  2 minutes to read (234 w ...

  10. 如何在 Windows 中设置 /3GB 启动开关

    备注: 只有在下列操作系统中才支持 /3GB 开关: Windows 2000 Advanced Server Windows 2000 Datacenter Server Windows Serve ...