当前位置:网站首页>playwright控制本地谷歌浏览打开,并下载文件
playwright控制本地谷歌浏览打开,并下载文件
2022-04-23 13:12:00 【两个南瓜饼】
控制谷歌浏览器打开我就直接上大佬的源码了,我主要聊聊下载的一些问题
from getpass import getuser
import time
from playwright.sync_api import sync_playwright
import requests
# 不出意外这个可以获取到你google的本地缓存文件
__USER_DATE_DIR_PATH__ = f"C:\\Users\\{getuser()}\\AppData\Local\Google\Chrome\\User Data"
# chrome.exe 的地址
__EXECUTABLE_PATH__ = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
playwright = sync_playwright().start()
browser = playwright.chromium.launch_persistent_context(
# 指定本机用户缓存地址
user_data_dir=__USER_DATE_DIR_PATH__,
# 指定本机google客户端exe的路径
executable_path=__EXECUTABLE_PATH__,
# 要想通过这个下载文件这个必然要开 默认是False
accept_downloads=True,
# 设置不是无头模式
headless=False,
bypass_csp=True,
slow_mo=10,
#跳过检测
args=['--disable-blink-features=AutomationControlled']
)
page = browser.new_page()
'''下载'''
# 打开下载器
with page.expect_download() as download_info:
#找到你要下载的东西,找到点击的元素,点击
downloadx = '//*[@id="_view_1545184311000"]/div[2]/div[4]/a[3]'
page.click(downloadx)
# 下载的东西
download = download_info.value
# 下载的路径
print(download.path())
# 下载的文件名
print(download.suggested_filename)
几个下载的问题
首先说明 download 存在三个可调用的方法,分别是
download.path()
download.save_as()
download.suggested_filename
一三就是文件名和路径,第二个可以设置存储路径,但是这个方法的使用是在下载后才可以使用,而且对D,E盘无访问权限,可以说没啥用。所以还是要知道playwright 的默认存储设置。
默认情况下,每次使用with as 打开下载会在C:\Users\ADMINI~1\AppData\Local\Temp\路径下创建一个 以 playwright-artifacts-cLLZs3 命名的文件夹,cLLZs3 是每次打开随机生成的。下载的文件的文件名也是随机的 GUID。例如 3c5b244f-4a05-44d7-bb03-0e9fc863abe2 20220422162554220422BPA2ZFNR40.zip
版权声明
本文为[两个南瓜饼]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_59938810/article/details/124350045
边栏推荐
- MySQL —— 16、索引的数据结构
- 初鉴canvas,展示个小小的小案例
- Mui close other pages and keep only the first page
- Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
- Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
- Golang implements a five insurance and one gold calculator with web interface
- Custom nail robot alarm
- Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
- SSM整合之pom.xml
- AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
猜你喜欢
JMeter operation redis
Custom nail robot alarm
2020最新Android大厂高频面试题解析大全(BAT TMD JD 小米)
The use of dcast and melt in R language is simple and easy to understand
解决虚拟机中Oracle每次要设置ip的问题
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation
【快排】215. 数组中的第K个最大元素
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
十万大学生都已成为猿粉,你还在等什么?
随机推荐
7_ The cell type scores obtained by addmodule and gene addition method are compared in space
Office 2021 installation package download and activation tutorial
[quick platoon] 215 The kth largest element in the array
[walking notes]
CSDN高校俱乐部“名师高校行”——湖南师范大学站
Uniapp image import local image not displayed
Hanlp word splitter (via spark)
MySQL —— 16、索引的数据结构
Analysis of the latest Android high frequency interview questions in 2020 (BAT TMD JD Xiaomi)
Proteus 8.10 installation problem (personal test is stable and does not flash back!)
4.22学习记录(你一天只做了水题是吗)
Important knowledge of network layer (interview, reexamination, term end)
Subscribe to Alibaba demo send business messages
nodejs + mysql 实现简单注册功能(小demo)
Customize classloader and implement hot deployment - use loadclass
Armv8m (cortex M33) MPU actual combat
web三大组件之Servlet
Metalama简介4.使用Fabric操作项目或命名空间
mui 微信支付 排坑
Use of Presto date function