;预配置项 url_l = http://www.a67.com/list/1/7/p. id = 1 ;初始页码 maxid = 129 ;最大页码 url_r = site = http://www.a67.com kind = 动作片 #Include sqliteDB.ahk #NoEnv OnExit, Exit ;初始化连接数据库 以便反复查询 DBFileName := A_ScriptDir . "\a67.db" global DB DB := new SQLiteDB if !DB.OpenDB(DBFileName) { MsgBox, 16, SQLite错误, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode ExitApp } ;首先检查初始化 if !IsObject(Query("select 1 from sqlite_master where name='movie'")) ;检查novel表 Exec("CREATE TABLE ""movie"" ( ""name"" TEXT(255), ""kind"" TEXT(255), ""uri"" TEXT(255),id"" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)") Loop % maxid-id { list := URLDownloadToVar(url_l id url_r,"utf-8") ;抓取小说列表 a := StrSplit(list,"`n","`r") ;分割行为数组 a_id = 283 ;直接跳到正文 Loop { a_id++ if (a_id>a.MaxIndex()) break ;抓取影片信息 if (RegExMatch(a[a_id],"^<a href=""(http://www\.a67\.com/movie/\d+)""[^>]*>([^<]*)</a>$",b)) { page:=b1,name:=b2,movie_id:=RegExReplace(b1,"http://www\.a67\.com/movie/(\d+)$","$1") ToolTip % name "," movie_id "," page a_id++ t_page := URLDownloadToVar(page,"utf-8") IfInString, t_page, cqmp4 uri = cqmp4 else ifInString, t_page, hdmp4 uri = hdmp4 else ifInString, t_page, mp4-g.gif uri = mp4 else continue t_down := URLDownloadToVar("http://www.a67.com/down/1_" movie_id "_1/" uri,"utf-8") ;获取下载页的下载地址 IfInString, t_down, 404.gif continue d := StrSplit(t_down,"`n","`r") Loop % d.MaxIndex() { if RegExMatch(d[A_Index],"^\s*.*(thunder://[^""]*)"".*迅雷下载</a></li>",e) { url:=e1 ToolTip % id "页:" name Exec("Insert INTO ""movie"" (""name"", ""kind"", ""uri"") VALUES ('" name "','" kind "','" url "')") ;插入数据 break } } } } id++ } MsgBox, Ok #z:: exit: DB.CloseDB() DB = ExitApp URLDownloadToVar(url, Encoding = "",Method="GET",postData=""){ ;网址,编码,请求方式,post数据 hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") if Method = GET { Try { hObject.Open("GET",url) hObject.Send() } catch e return -1 } else if Method = POST { Try { hObject.Open("POST",url,False) hObject.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") hObject.Send(postData) } catch e return -1 } if (Encoding && hObject.ResponseBody) { oADO := ComObjCreate("adodb.stream") oADO.Type := 1 oADO.Mode := 3 oADO.Open() oADO.Write(hObject.ResponseBody) oADO.Position := 0 oADO.Type := 2 oADO.Charset := Encoding return oADO.ReadText(), oADO.Close() } return hObject.ResponseText } ;构造查询SQL函数 Query(SQL){ ;返回数组 global DB ;全局 if !DB.GetTable(SQL, Result) MsgBox, 16, SQLite错误: 获取结果, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode "`n" SQL if (Result.HasRows) { return Result.Rows } } ;构造执行SQL函数 Exec(SQL){ ;返回执行影响行数 global DB ;全局 if !DB.Exec(SQL) MsgBox, 16, SQLite错误: 获取结果, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode "`n" SQL return DB._Changes() }
60 queries in 2.120 seconds |