数组集合、文件操作、字符串命令、数据筛选等等
;今天给大家带来一个自动过滤保存知乎网有用文章内容的脚本
;还是对我本人有用,其他人要用的话,可能需要更改很多参数或地址
;大家看看我的思路一起讨论讨论,具体如下:
Home::
Run E:\Linteng\software\Chrome\App\chrome.exe "www.zhihu.com"
WinWait, ahk_class Chrome_WidgetWin_1, Chrome Leg
;~ MouseMove, 1379, 177
Sleep, 1000
MouseGetPos, a, b
Label1:
PixelGetColor, c, 1379, 177 ;根据某一点的颜色变化,来判断网页的加载情况
RegExMatch(c, "\w{6}$", d)
;~ note(d)
If(d="CC5200")
{
;~ MsgBox, 0, , 加载完毕, 1
shcs = 0 ;设置辨认阅读全文位置的循环次数为0,如果超过三次,就自动退出脚本
Goto, Label2
}
Else
Sleep, 300
Goto, Label1
Return
Label2:
;~ MsgBox, 0, , 接着猥琐, 2
;------------------------------点击展开阅读全文-----------------------
t1:=A_TickCount, X:=Y:=""
Text:="|<阅读全文>*132$71.000000000000000003000000E00206003U00lzz60A00D000nzy6Tzs0v0DUk0ACzzk3X0T1s8M81U0S3U2Essk0301k3U0Un1UDzyD03k17znTTzxs01s2A1ay40NDzwU4M3AA6MkTzs08k6MNWlU0k00FzwkllU01U00XP1VUn0030010a/3TzyDzz023AK6zzwTzy046MgA0k00M008MnMO3s00k00FUykwCs01U0Qg01VvswTzzvt01z7T0Qzzzn201w4M0M0000000000000000000000000001"
Text.="|<阅读全文2>*133$71.00000000000000000000000000000A000001U0080M00C0037zwM0k00y003DzsNzzU3i0z300kPzz0CC1y3UVUU600sC05XXX00A07UD0/1A60zzww07UKTzAxzznk07Ugk6NsM0azzv0NUAkkQV1zzk0n0NVWB203001bzn332006003Bg663A00A0063MgBzzszzy0A4lsPzzlzzw0MNXkk1U01U00lX5VY7U03005a3v3svk0601vM067bVlzzzja03wTw1vzzzAA07kFU0U0000000000000001"
Text.="|<阅读3>*132$71.000000000000000000U000004000U1000k00QTznU2003k00QzzXbzy0Bk3UM033jzw1lk70I6620E071k0AAAA00U0w0s0MAkM3zzbU0w0nzsrbzzS00w1a0lj106rzzM3A1X21aADzy06M364NgM0A00AzyA8QM00M00NgUMEAk00k00kN6kbzz3zzk1UmBVDzy7zzU334P20A00600668q4Uw00A00AsTAD3i00M04P00sQyD7zzysk0TVrk7DzzwVU0z16060000000000000000000000000001"
Text.="|<阅读4>*134$71.00000000000k0000E000001U00E0U00M001bztk1001s003DzlXzy06s1zzU1Vbzw0ss3zz1310803UM0M06600E0S0Q0k2MA1zznk0S0U7wPnzzj00C1U08rVU39zzg300FV0n63zz0310X28q8060063z64AA00A006CEA84E00M006oXMHzzVzzs0796kbzz3zzk0S2BV06003001z4P2ES00600D6Da5Xb00A03s00ASS7XzzzT00Dkvs3bzzyE00TV602000000000000000000000000000001"
if (ok:=FindText(X, Y, 110, 257, 1660, 911, 0.3, 0.3, Text))
{
; FindText().Click(X, Y, "L")
}
MouseMove, %x%, %y%
If(x="")
{
shcs += 1
If(shcs = 12){
MsgBox, , 0, 你还是重新编辑吧, 1
ExitApp
}
Sleep, 200
Goto, Label2
ExitApp
}
Clipboard := ""
Click
Sleep, 500
Send, ^a
Send, {LControl Down}{c}
Send, {LControl Up}
ClipWait
ControlClick, x36 y1010, ahk_class Chrome_WidgetWin_1, Chrome Leg ;点击一下空白处,退出全选状态
Wdizhi = % "E:\Linteng\学习 修行\笔记摘抄截图\阅读截图\知乎\" A_MM A_DD "工作文档.txt"
FileAppend, %Clipboard%`n, %Wdizhi%
dizhi = % Wdizhi
Bthang=
s=
ContentH2=
ConGroup2 := []
;-----------------第一次循环,确定标题的具体位置----------
Loop, Read, %dizhi%
{
ContentH2 = % A_LoopReadLine ;记录每一行的内容
ConGroup2.InsertAt(A_Index, ContentH2) ;-----------每一行内容加入数组
;~ if InStr(A_LoopReadLine, "人赞同了该回答"){
If (A_Loopreadline ~= ("人赞同了该回答|人赞同了该文章")){
Bthang = % A_Index - 5
BthangC = % ConGroup2[(Bthang)] ;----------判断这个标题行有多长,很短的话就忽略这一行
;~ MsgBox % StrLen(BthangC)
If(StrLen(BthangC) < 4)
Bthang += 1
Break
}
}
;----------------第二次循环,去除标题行以上的所有内容----------
ContentH =
ConGroup := []
Loop, Read, %dizhi%
{
If(A_Index >= Bthang){
ContentH = % A_LoopReadLine ;记录每一行的内容
}
ConGroup.InsertAt(A_Index, ContentH) ;-----------每一行内容加入数组
}
For k, v in ConGroup
s .= v . "`n" ;-----------一起弹出来
ycbt=
ycbt = % s
ycbt := RegExReplace(ycbt,"\n+","`n") ;移除空行
;---------------第三次循环,确定结尾具体位置-------------------
ycjw=
Jwhang=
Loop, parse, ycbt, `n, `r ;按行读取变量内容
{
;~ if InStr(A_LoopField, "发布于") Or InStr(A_LoopField, "编辑于"){
If (A_loopfield ~= ("发布于|编辑于")){
Jwhang = % A_Index
Break
}
}
;---------------第四次循环,去除结尾内容---------------------
ContentH =
s=
ConGroup2 := []
Loop, parse, ycbt, `n, `r ;按行读取变量内容
{
If(A_Index <= Jwhang){
ContentH = % A_LoopField ;记录每一行的内容
ConGroup2.InsertAt(A_Index, ContentH) ;-----------每一行内容加入数组
}
Continue
}
For k, v in ConGroup2
s .= v . "`n" ;-----------一起弹出来
ycbt=
ycbt = % s
;~ note(s)
;~ Return
;---------创建一个标题名称------------------
BTName=
Loop, parse, ycbt, `n, `r ;按行读取变量内容
{
Length=
BTName = % A_LoopField
Length := StrLen(BTName) ;------获取数据的长度
If(Length > 5)
Break
}
;----------以下开始创建txt文件------------
;~ note(ycbt)
;~ Return
;~ MsgBox % BTName
dizhi=
dizhi = % "E:\Linteng\学习 修行\笔记摘抄截图\阅读截图\知乎\" A_MM A_DD BTName ".txt"
Sleep, 100
FileAppend, %ycbt%`n, %dizhi%
Sleep, 100
FileDelete, %Wdizhi%
Sleep, 100
WinActivate, 知乎 ahk_class CabinetWClass, FolderView
WinMinimize, ahk_class Chrome_WidgetWin_1, Chrome Leg
return
#Include <正则全局模式> ;我忘记这是哪一段代码附加上来的包含了,就放着好了。
Insert::Goto, Label2 ;有时候点击不到阅读全文,加一个手动点击
End::ExitApp
特别感谢【社区元神】AHK1-僵尸!!画龙点睛般的相助提点!
怎么文章上的代码块中间一部分全部是黄色的,奇怪~
谢谢大神分享,学习
谢谢楼主分享