当前位置:网站首页>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://yzsam.com/2022/04/202204231312102892.html
边栏推荐
- The first lesson is canvas, showing a small case
- Introduction to metalama 4 Use fabric to manipulate items or namespaces
- [dynamic programming] 221 Largest Square
- 超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
- FFmpeg常用命令
- "Play with Lighthouse" lightweight application server self built DNS resolution server
- 初鉴canvas,展示个小小的小案例
- CMSIS cm3 source code annotation
- Nodejs + websocket cycle small case
- (个人)最近项目开发后存在的系统漏洞整理
猜你喜欢

CMSIS cm3 source code annotation

jmeter操作redis

filter()遍历Array异常友好

在 pytorch 中加载和使用图像分类数据集 Fashion-MNIST

Loading and using image classification dataset fashion MNIST in pytorch

Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘

普通大学生如何拿到大厂offer?敖丙教你一招致胜!

Data warehouse - what is OLAP

数据仓库—什么是OLAP

The filter() traverses the array, which is extremely friendly
随机推荐
51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
[notes de marche]
[walking notes]
Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
FFmpeg常用命令
Mui + hbuilder + h5api simulate pop-up payment style
Install nngraph
Translation of attention in natural language processing
7_Addmodule和基因加和法add 得到的细胞类型打分在空间上空转对比
Read the data in Presto through sparksql and save it to Clickhouse
mysql 基本语句查询
[untitled] make a 0-99 counter, P1 7 connected to key, P2 connected to nixie tube section, common anode nixie tube, P3 0,P3. 1. Connect the nixie tube bit code. Each time you press the key, the nixie
Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
async void 導致程序崩潰
Office 2021 installation package download and activation tutorial
uniapp image 引入本地图片不显示
decast id.var measure. Var data splitting and merging
安装nngraph
Timing role in the project
STD:: shared of smart pointer_ ptr、std::unique_ ptr