python调用游览器下载文件

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

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()

#####################

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值