当前位置:网站首页>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
边栏推荐
- mui 关闭其他页面,只保留首页面
- MySQL -- 16. Data structure of index
- 5 tricky activity life cycle interview questions. After learning, go and hang the interviewer!
- nodeJs + websocket 循环小案例
- FFmpeg常用命令
- Scons build embedded ARM compiler
- 初鉴canvas,展示个小小的小案例
- AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
- Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
- Timing role in the project
猜你喜欢

解决虚拟机中Oracle每次要设置ip的问题

Nodejs + Mysql realize simple registration function (small demo)

web三大组件之Servlet

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

Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched

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

R语言中dcast 和 melt的使用 简单易懂

【官宣】长沙软件人才实训基地成立!

100 lectures on practical application cases of Excel (VIII) - report connection function of Excel

Install nngraph
随机推荐
超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
"Play with Lighthouse" lightweight application server self built DNS resolution server
three. JS text ambiguity problem
普通大学生如何拿到大厂offer?敖丙教你一招致胜!
Data warehouse - what is OLAP
AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
web三大组件之Filter、Listener
EMMC / SD learning notes
【微信小程序】flex布局使用记录
8086 of x86 architecture
Translation of multi modal visual tracking: review and empirical comparison
Nodejs + Mysql realize simple registration function (small demo)
AUTOSAR from introduction to mastery 100 lectures (87) - key weapon of advanced EEA - AUTOSAR and DDS
Complete project data of UAV apriltag dynamic tracking landing based on openmv (LabVIEW + openmv + apriltag + punctual atom four axes)
jmeter操作redis
The use of dcast and melt in R language is simple and easy to understand
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
这几种 VSCode 扩展是我最喜欢的
缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
Introduction to metalama 4 Use fabric to manipulate items or namespaces