Skip to content

Instantly share code, notes, and snippets.

@ycrao
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycrao/68527cbbe058f1e644fd to your computer and use it in GitHub Desktop.
Save ycrao/68527cbbe058f1e644fd to your computer and use it in GitHub Desktop.
每日一文采集器
;filename:DownloadEssay.ahk
;Author:sunshine
;QQ:837454876
DownloadEssay(filename, today, israndom, templatepath, filepath, url)
{
URLDownloadToFile, %url%, mobile
FileRead, html, *P65001 mobile ;*P65001:utf-8编码 *P936 gb2312编码
RegExMatch(html, "(?<=<title>)(.*)(?=</title>)", _htmltitle)
RegExMatch(html, "(?<=div\sclass=""container"">)(.*)(?=<div class=""nav"")",_essay)
StringReplace, _essay, _essay, %A_Tab%, , A
StringReplace, _essay, _essay, `r, , A
StringReplace, _essay, _essay, `n, , A
FileDelete, mobile
FileRead, template, *P65001 %templatepath%\book.tplt
Nowtime = %today% %A_Hour%:%A_Min%
StringReplace, template, template, #title#, %_htmltitle%, A
if israndom ;随机文章处理
{
StringReplace, template, template, #thesign#, 随机文章%filename%, A
StringReplace, template, template, #content#, %_essay%, A
StringReplace, template, template, #thetime#, %NowTime%, A
FileAppend, %template%, temp, UTF-8
FileMove, temp, %filepath%\%filename%.html, 1
}
else
{
StringReplace, template, template, #thesign#, %today%, A
StringReplace, template, template, #content#, %_essay%, A
StringReplace, template, template, #thetime#, %NowTime%, A
FileAppend, %template%, temp, UTF-8
FileMove, temp, %filepath%\%filename%.html, 1
MsgBox, 4, 是否打开下载文件, 今日文章下载完毕,是否打开该文章`r`n点击是打开,否取消
IfMsgBox Yes
Run, %filepath%\%filename%.html
else return
}
}
;Title:每日一文采集器
;filename:mryw.ahk
;Author:sunshine
;QQ:837454876
#Include DownloadEssay.ahk
IndexURL=http://meiriyiwen.com/index/mobile
RandomURL=http://meiriyiwen.com/random/mobile
DownloadPath=%A_ScriptDir%\OneEssayPerDay
TemplatePath=%A_ScriptDir%\template
RandomEssayPath=%DownloadPath%\RandomEssay
ifNotExist DownloadPath
FileCreateDir , %DownloadPath%
FileCopyDir, %TemplatePath%\css, %DownloadPath%\css
ifNotExist RandomEssayPath
FileCreateDir , %RandomEssayPath%
FileCopyDir, %TemplatePath%\css, %RandomEssayPath%\css
Gui, Add, Button, x40 y40 w150 h20 gDownRandom, 采集随机文章20篇
Gui, Add, Button, x220 y40 w100 h20 gDownToday, 采集今日文章
Gui, Add, Text, x40 y100 w300 h45, 注意:采集随机文章可能会采集到相同重复的内容`r`n联系作者:QQ:837454876 AHK交流群号:12732288
; Generated using SmartGUI Creator for SciTE
Gui, Show, w350 h150, 每日一文采集器
return
DownToday:
aDay := A_YYYY A_MM A_DD
ToDay = %A_YYYY%-%A_MM%-%A_DD%
IfExist, %DownloadPath%\%aDay%.html
{
TrayTip, 每日一文, %aDay%文章已存在, 5, 1
MsgBox, 4, 是否重新下载, 每日一文 %aDay% 文章已存在`r`n是否重新下载,点击是重新下载,否取消下载
IfMsgBox Yes
{
DownloadEssay(aDay, ToDay, 0, TemplatePath, DownloadPath, IndexURL)
}
else return
}
else DownloadEssay(aDay, ToDay, 0, TemplatePath, DownloadPath, IndexURL)
return
DownRandom:
TrayTip, 请耐心等待, 正在采集随机文章, 10, 1
loop , 20
{
RandomFileName := A_Now
ToDay = %A_YYYY%-%A_MM%-%A_DD%
DownloadEssay(RandomFileName, ToDay, 1, TemplatePath, RandomEssayPath, RandomURL)
Sleep, 1500
}
MsgBox, 20篇随机文章下载完毕,打开%RandomEssayPath%即可看到
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment