【Web_接口爬虫_Python3_百度一下_Options&ChromeOptions】百度一下,无头浏览器调试

#!/usr/bin/env/python3
# -*- coding:utf-8 -*-
'''
Author:leo
Date&Time:2021/4/15 12:19
Project:python  FileName:20210415_无头浏览器_selenium.py
Comment:无头浏览器验证

'''
from selenium import webdriver
from selenium.webdriver.chrome.options import Options  #实现无可视化界面
from selenium.webdriver import ChromeOptions  #实现规避检测

# 实现无可视化界面
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 实现规避检测
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 创建驱动
driver = webdriver.Chrome(executable_path=r"D:\Mytest\Svnbucket\python\config\pycharm_config\brower_driver\chromedriver.exe", chrome_options=chrome_options, options=option)
driver.get('https://www.baidu.com')
print(driver.title)
print(driver.page_source.encode('gbk', 'ignore').decode('gbk'))
driver.quit()

百度一下,你就知道
<html><head><script async="" src="https://passport.baidu.com/passApi/js/wrapper.js?cdnversion=1618450291615&amp;_=1618450291068"></script><script type="text/javascript" charset="utf-8" src="https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superui/js/ubase_5a7b0933.js"></script><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta content="always" name="referrer"><meta name="theme-color" content="#2932e1"><meta name="description" content="全球最大的中文搜索引擎、致力于让网民更便捷地获取信息,找到所求。百度超过千亿的中文网页数据库,可以瞬间找到相关的搜索结果。"><link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索"><link rel="icon" sizes="any" mask="" href="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg"><link rel="dns-prefetch" href="//dss0.bdstatic.com"><link rel="dns-prefetch" href="//dss1.bdstatic.com"><link rel="dns-prefetch" href="//ss1.bdstatic.com"><link rel="dns-prefetch" href="//sp0.baidu.com"><link rel="dns-prefetch" href="//sp1.baidu...

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值