1.查看游览器版本

2.下载chrome 游览器驱动
地址:http://chromedriver.storage.googleapis.com/index.html

3.驱动放置 chrome 安装路径

4.编写代码读取url,调用chrome下载文件
import os
import sys
import time
from selenium import webdriver
browser = webdriver.Chrome(‘C:\Users\Conan\AppData\Local\Google\Chrome\Application\chromedriver.exe’)
url_list = []
def readtxt():
txtfile = open(‘D:\picture\story.txt’,‘r’,encoding=‘utf-8’)
line = txtfile.readline()
while line:
content = line.split()
geturl_list = content[2]
url_list.append(geturl_list)
line = txtfile.readline()
txtfile.close()
def getfile():
count = len(open(‘D:\picture\story.txt’,‘r’,encoding=‘utf-8’).readlines())
# print(count)
for i in range(count):
fileurl=url_list[i]
browser.get(fileurl)
time.sleep(6)
readtxt()
getfile()
#####################

这篇博客介绍了如何通过Python的Selenium库自动化控制Chrome浏览器,包括检查浏览器版本、下载Chrome驱动并放置到正确路径,以及编写代码从文本文件中读取URL列表,逐个加载页面并等待下载完成。这是一个实用的自动化脚本示例,适用于批量处理网页下载任务。

被折叠的 条评论
为什么被折叠?



