gpt4 book ai didi

google-chrome - Apple 脚本在 Chrome 上打开网页并复制文本

转载 作者:行者123 更新时间:2023-12-04 18:15:52 25 4
gpt4 key购买 nike

嗯,这是我的问题,我尝试在 AppleScript 中编写代码,以便打开网页并复制所有文本,然后将其保存到变量中,并稍后使用该变量,问题是我已经这样做了对于 safari 来说效果很好,但是对于 chrome 我不知道该怎么做,我今天开始学习这种语言,所以任何帮助将不胜感激。这是我到目前为止所拥有的

    tell application "Google Chrome"
activate
set theurl to "http://www.webpage.com"
if (count every window) = 0 then
make new window
end if

set found to false
set theTabIndex to -1
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
if theTab's URL = theurl then
set found to true
exit repeat
end if
end repeat

if found then
exit repeat
end if
end repeat

if found then
tell theTab to reload
set theWindow's active tab index to theTabIndex
set index of theWindow to 1
else
tell window 1 to make new tab with properties {URL:theurl}
end if
end tell


tell application "Google Chrome"
tell tab 6 of window 1 to select all
tell tab 6 of window 1 to copy selection
--in here I dont know how to set the variable with the text i just copied
end tell

最佳答案

您可以获得剪贴板的纯文本版本,其中剪贴板为文本

tell application "Google Chrome" to tell tab 1 of window 1
select all
copy selection
end tell

set t to the clipboard as text

您也可以使用document.body.innerText:

tell application "Google Chrome" to tell tab 1 of window 1
set t to execute javascript "document.body.innerText"
end tell

关于google-chrome - Apple 脚本在 Chrome 上打开网页并复制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11735471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com