爬虫day4 selenium高级用法
一、selenium常见设置
from selenium.webdriver import Chrome, ChromeOptions
1.创建配置对象
options = ChromeOptions()
2.添加配置
1)取消测试环境
options.add_experimental_option('excludeSwitches', ['enable-automation'])
2)取消图片加载
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
3.创建浏览器对象
b = Chrome(options=options)
4.打开网页
b.get('https://www.jd.com')
二、selenium页面滚动
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time
options = ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
b = Chrome(options=options)
# 打开京东
b.get('https://www.jd.com')
# 搜索框输入商品名
search = b.find_element_by_id('key')
search.send_keys('运动鞋')
sear