shell 脚本工作,捕获网页作为mht文件,但chrome正在删除

rseugnpd  于 2023-03-13  发布在  Shell
关注(0)|答案(2)|浏览(82)

下载工作正常,但谷歌删除它的时刻,我选择“显示在Finder”-
Removed File
安全浏览设置为“无保护(不推荐)”
我的目标是创建一个简单的脚本,用于下载webarchive并为其添加时间戳,以便每天使用cron或iCal运行
运行脚本似乎工作良好,下载网页作为存档,但Chrome不知何故删除了下载
任何帮助都很感激

#!/bin/bash

# Set the URL of the website to open in Chrome
URL="https://thescottsdaleherald.com/"

# Set the directory to save the web archive file to
SAVE_DIR="$HOME/Desktop/"

# Get the current date in the format "day-month-year"
DATE=$(date +'%H-%d-%m-%Y')

# Open the website in Chrome
open -a "Google Chrome" "$URL"

# Wait for Chrome to load the website
sleep 5

# Get the title of the page
PAGE_TITLE=$(osascript -e 'tell application "Google Chrome" to return title of active tab of window 1')

# Replace any commas in the page title with hyphens
PAGE_TITLE=${PAGE_TITLE//,/}

# Save the web archive file with the format "pagetitle,day,month,year.webarchive"
FILE_NAME="$PAGE_TITLE,$DATE.mht"
FULL_PATH="$SAVE_DIR/$FILE_NAME"
osascript -e 'tell application "Google Chrome" to save active tab of window 1 in file "'"$FULL_PATH"'" '
raogr8fs

raogr8fs1#

根据AppleScript Guide,文件对象的结构为

file "VolumeName:FolderName:SubfolderName:FileName"

因此,基本上,您的脚本需要2个更新:
1.将卷名添加到保存_DIR的开头,例如
SAVE_DIR="Macintosh SSD/$HOME/Desktop"
请确保使用您自己的卷名
1.调用FULL_PATH时,将所有/替换为:
...to save active tab of window 1 in file "'"${FULL_PATH//\//:}"'" '

83qze16e

83qze16e2#

解决日期:
这里是最终脚本-它的好终于有一个每日脚本-非常感谢!

#!/bin/bash

# Set the URL of the website to open in Chrome
URL="https://thescottsdaleherald.com/"

# Set the directory to save the web archive file to
SAVE_DIR="BigSur/$HOME/Desktop"

# Get the current date in the format "day-month-year"
DATE=$(date +'%H-%d-%m-%Y')

# Open the website in Chrome
open -a "Google Chrome" "$URL"

# Wait for Chrome to load the website
sleep 5

# Get the title of the page
PAGE_TITLE=$(osascript -e 'tell application "Google Chrome" to return title of active tab of window 1')

# Replace any commas in the page title with hyphens
PAGE_TITLE=${PAGE_TITLE//,/}

# Save the web archive file with the format "pagetitle,day,month,year.html"
FILE_NAME="$PAGE_TITLE,$DATE.html"
FULL_PATH="$SAVE_DIR/$FILE_NAME"
osascript -e 'tell application "Google Chrome" to save active tab of window 1 in file "'"${FULL_PATH//\//:}"'" '

相关问题