当前位置:网站首页>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
边栏推荐
- Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
- jmeter操作redis
- 「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
- [notes de marche]
- LeetCode_DFS_中等_695.岛屿的最大面积
- Three channel ultrasonic ranging system based on 51 single chip microcomputer (timer ranging)
- Pyqt5 store opencv pictures into the built-in sqllite database and query
- AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
- (个人)最近项目开发后存在的系统漏洞整理
- decast id.var measure.var数据拆分与合并
猜你喜欢

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)

AUTOSAR from introduction to mastery 100 lectures (51) - AUTOSAR network management

100 GIS practical application cases (52) - how to keep the number of rows and columns consistent and aligned when cutting grids with grids in ArcGIS?

Mui + hbuilder + h5api simulate pop-up payment style

Learning notes of AMBA protocol

叮~ 你的奖学金已到账!C认证企业奖学金名单出炉

ESP32 VHCI架构传统蓝牙设置scan mode,让设备能被搜索到

Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)

MySQL5.5安装教程

AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
随机推荐
Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
Learning notes of AMBA protocol
Filter and listener of three web components
Mui close other pages and keep only the first page
SPI NAND flash summary
MySQL -- 16. Data structure of index
100 GIS practical application cases (52) - how to keep the number of rows and columns consistent and aligned when cutting grids with grids in ArcGIS?
Connect orcale
Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
"Play with Lighthouse" lightweight application server self built DNS resolution server
数据仓库—什么是OLAP
Hanlp word splitter (via spark)
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
HQL statement tuning
FFmpeg常用命令
[dynamic programming] 221 Largest Square
mui 关闭其他页面,只保留首页面
C语言之字符串与字符数组的区别
Proteus 8.10 installation problem (personal test is stable and does not flash back!)