当前位置:网站首页>Playwright controls local Google browsing to open and download files
Playwright controls local Google browsing to open and download files
2022-04-23 13:12:00 【Two pumpkin cakes】
Control Google browser to open and I'll go directly to Big guy's source code 了 , I mainly talk about some problems of downloading
from getpass import getuser
import time
from playwright.sync_api import sync_playwright
import requests
# Not surprisingly, this can get you google Local cache file for
__USER_DATE_DIR_PATH__ = f"C:\\Users\\{getuser()}\\AppData\Local\Google\Chrome\\User Data"
# chrome.exe The address of
__EXECUTABLE_PATH__ = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
playwright = sync_playwright().start()
browser = playwright.chromium.launch_persistent_context(
# Specify the local user cache address
user_data_dir=__USER_DATE_DIR_PATH__,
# Specify native google client exe The path of
executable_path=__EXECUTABLE_PATH__,
# If you want to download files through this, you must open The default is False
accept_downloads=True,
# Setting is not headless mode
headless=False,
bypass_csp=True,
slow_mo=10,
# Skip detection
args=['--disable-blink-features=AutomationControlled']
)
page = browser.new_page()
''' download '''
# Open the downloader
with page.expect_download() as download_info:
# Find what you want to download , Find the clicked element , Click on
downloadx = '//*[@id="_view_1545184311000"]/div[2]/div[4]/a[3]'
page.click(downloadx)
# Download something
download = download_info.value
# Download path
print(download.path())
# Download file name
print(download.suggested_filename)
Several download problems
First of all download There are three callable methods , Namely
download.path()
download.save_as()
download.suggested_filename
One or three is the file name and path , Second, you can set the storage path , But this method can only be used after downloading , And right D,E Disk has no access , It's useless . So you still need to know playwright Default storage settings for .
By default , Each use with as Opening the download will be in C:\Users\ADMINI~1\AppData\Local\Temp\ Create a With playwright-artifacts-cLLZs3 Named folder ,cLLZs3 It is generated randomly every time you open . The file name of the downloaded file is also Random GUID. for example 3c5b244f-4a05-44d7-bb03-0e9fc863abe2 20220422162554220422BPA2ZFNR40.zip
版权声明
本文为[Two pumpkin cakes]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231312102892.html
边栏推荐
- The filter() traverses the array, which is extremely friendly
- [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
- How to convert opencv pictures to bytes
- mui + hbuilder + h5api模拟弹出支付样式
- uniapp image 引入本地图片不显示
- Connect orcale
- 内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
- Loading and using image classification dataset fashion MNIST in pytorch
- “湘见”技术沙龙 | 程序员&CSDN的进阶之路
- 2021年6月程序员工资统计,平均15052元,你拖后腿了吗?
猜你喜欢

十万大学生都已成为猿粉,你还在等什么?

Hbuilderx + uniapp packaging IPA submission app store stepping on the pit

Request和Response及其ServletContext总结
![[51 single chip microcomputer traffic light simulation]](/img/70/0d78e38c49ce048b179a85312d063f.png)
[51 single chip microcomputer traffic light simulation]

【微信小程序】flex布局使用记录

Imx6ull QEMU bare metal tutorial 1: GPIO, iomux, I2C

melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化

Melt reshape decast long data short data length conversion data cleaning row column conversion

“湘见”技术沙龙 | 程序员&CSDN的进阶之路

在 pytorch 中加载和使用图像分类数据集 Fashion-MNIST
随机推荐
SQL exercise question 1
「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
[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
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
9419 page analysis of the latest first-line Internet Android interview questions
HQL find the maximum value in a range
HQL statement tuning
(个人)最近项目开发后存在的系统漏洞整理
nodeJs + websocket 循环小案例
Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
Data warehouse - what is OLAP
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)
Custom nail robot alarm
vscode小技巧
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
jmeter操作redis
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
MySQL -- 16. Data structure of index
Uniapp image import local image not displayed
【行走的笔记】