python+selenium+webdriver环境搭建相关文档
python+selenium+webdriver环境搭建相关
环境搭建 https://www.cnblogs.com/wulixia/p/11200023.html
Chromedriver下载地址 http://npm.taobao.org/mirrors/chromedriver/
Web API 接口参考 https://developer.mozilla.org/zh-CN/docs/Web/API
Selenium with Python中文翻译文档 https://selenium-python-zh.readthedocs.io/en/latest/index.html
使用webdriver操作浏览器 https://blog.csdn.net/zh175578809/article/details/76359371
示例: 打开网址查找id位置并截屏
# 依赖包
pip install selenium
pip install Pillow
----------------------------------------------------------------------------
#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
from PIL import ImageGrab
import time
# 参数
AD_URL = 'https://www.pconline.com.cn/'
AD_ID = 'ad478316'
AD_IMG_PATH = 'd:/Project-python/ass/imgs/'
def test():
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=option)
# 浏览器窗口最大化
driver.maximize_window()
# 打开页面
driver.get(AD_URL)
print(driver.title)
# 定位元素
adElement = driver.find_element_by_id(AD_ID)
driver.execute_script('arguments[0].scrollIntoView();', adElement)
time.sleep(3)
# print(adElement)
# 浏览器截屏
# driver.get_screenshot_as_file('1.png')
# 系统截屏
im = ImageGrab.grab()
imgName = str(time.time()) + '.jpg'
im.save(AD_IMG_PATH + imgName, 'jpeg')
print('截图成功~ 图片 ' + AD_IMG_PATH + imgName)
time.sleep(3)
# 关闭
driver.close()
if __name__ == "__main__":
test()
-------------已经触及底线 感谢您的阅读-------------