页面识别.au3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #RequireAdmin
  2. #Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
  3. #AccAu3Wrapper_Outfile=页面识别x86.exe
  4. #AccAu3Wrapper_Outfile_x64=页面识别x64.exe
  5. #AccAu3Wrapper_Compile_Both=y
  6. #AccAu3Wrapper_Res_Language=2052
  7. #AccAu3Wrapper_Res_requestedExecutionLevel=None
  8. #EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
  9. #Region ;**** 编译指令由 by AutoIt3Wrapper_GUI 创建 ****
  10. #EndRegion ;**** 编译指令由 by AutoIt3Wrapper_GUI 创建 ****
  11. #Region ;**** 参数创建于 ACNWrapper_GUI ****
  12. #EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
  13. #include <array.au3>
  14. #include <GUIConstants.au3>
  15. #include <IE.au3>
  16. ;#include<setdefault.au3>
  17. #include <file.au3>
  18. #include <MsgBoxConstants.au3>
  19. #include <excel.au3>
  20. #include <_html.au3>
  21. #include <sfilter.au3>
  22. #include <inet.au3>
  23. ;Opt("CaretCoordMode", 1)
  24. ;Opt("ExpandEnvStrings", 0)
  25. Opt("ExpandVarStrings", 0)
  26. ;Opt("GUICloseOnESC", 0)
  27. ;Opt("GUICoordMode", 1)
  28. ;Opt("GUIDataSeparatorChar","|")
  29. ;Opt("GUIOnEventMode", 0)
  30. ;Opt("GUIResizeMode",0)
  31. ;Opt("GUIEventOptions",1)
  32. Opt("MouseClickDelay", 10)
  33. Opt("MouseClickDownDelay", 10)
  34. Opt("MouseClickDragDelay", 250)
  35. Opt("MouseCoordMode", 1)
  36. Opt("MustDeclareVars", 0)
  37. Opt("PixelCoordMode", 1)
  38. Opt("SendAttachMode", 0)
  39. Opt("SendCapslockMode", 1)
  40. Opt("SendKeyDelay", 5)
  41. Opt("SendKeyDownDelay", 1)
  42. Opt("TCPTimeout", 100)
  43. Opt("TrayAutoPause", 1)
  44. Opt("TrayIconDebug", 0)
  45. Opt("TrayIconHide", 0)
  46. Opt("TrayMenuMode", 0)
  47. Opt("TrayOnEventMode", 0)
  48. Opt("WinDetectHiddenText", 0)
  49. Opt("WinSearchChildren", 1)
  50. Opt("WinTextMatchMode", 1)
  51. Opt("WinTitleMatchMode", 1)
  52. Opt("WinWaitDelay", 250)
  53. Global $input1
  54. Global $g_idGUIProg
  55. Global $oIE = 0
  56. Global $filepath = @ScriptDir
  57. Global $size = 0 ;difine listfile size
  58. Global $list_file_url = @ScriptDir & "\任务列表.txt" ;页面提取的文件
  59. Global $line_url = "http://guba.eastmoney.com/"
  60. Global $state = ""
  61. Global $stock_id = ""
  62. Global $resault_dir = @ScriptDir & "\data"
  63. Global $ie_all_span = @extended
  64. Global $ie_all_div = @extended
  65. Global $oEventObject
  66. Global $SIZES = 0
  67. Global $CURPID = 0
  68. Global $TXTDATA = ""
  69. Global $oExcel, $oWorkbook
  70. Global $cur_process = 0
  71. ;========================================
  72. Global $tmpfile = @ScriptDir & "\tmp.tmp"
  73. $source = "dbc.data"
  74. $target = "任务列表.txt"
  75. $resault_dir = @ScriptDir
  76. Global $oIE = 0
  77. Global $ierw_url = ""
  78. ;$oIE = ObjCreate("InternetExplorer.Application.1")
  79. _IELoadWaitTimeout(100)
  80. Global $oIE = _IECreate("http://guba.eastmoney.com")
  81. ;========================================
  82. While 1
  83. If FileExists("任务列表.txt") And _FileCountLines("任务列表.txt") > 0 Then
  84. $uulist = @ScriptDir & "\任务列表.txt"
  85. $list_file_url = @ScriptDir & "\任务列表.txt"
  86. Else
  87. $succ = FileCopy($source, $target)
  88. If $succ = 1 Then
  89. Global $uulist = $target
  90. Global $starturl = "http://guba.eastmoney.com/list,"
  91. MsgBox($MB_SYSTEMMODAL, "", "创建第一次运行列表.", 1)
  92. EndIf
  93. EndIf
  94. MsgBox($MB_SYSTEMMODAL, "网址", "ok列表存在,从上次任务继续.", 1)
  95. start_job($oIE) ;执行打开窗口
  96. WEnd
  97. ;=============================================
  98. Func ierw($ierw_url)
  99. Local $netdata = InetGet($ierw_url, $tmpfile)
  100. $htms = FileRead($tmpfile)
  101. _IEBodyWriteHTML($oIE, $htms)
  102. FileClose($tmpfile)
  103. EndFunc ;==>ierw
  104. removeIE()
  105. Func start_job($oIE)
  106. Local $iMsg
  107. Local $hGUIMain
  108. $hGUIMain = GUICreate("IE BROWSER", 600,400)
  109. $input1 = GUICtrlCreateInput("show" & @CRLF, 10, 20, 580, 300)
  110. $g_idGUIProg = GUICtrlCreateProgress(10, 5, 580, 10)
  111. Local $idGUIExit = GUICtrlCreateButton("退出采集", 250, 450, 80, 30)
  112. GUISetState() ;Show GUI
  113. Sleep(1000) ; Give it some time to load the web page
  114. GUISwitch($hGUIMain) ; Switch back to our GUI in case IE stole the focus
  115. ; We prepare the Internet Explorer as our test subject
  116. ieobjint()
  117. While 1
  118. $iMsg = GUIGetMsg()
  119. If $iMsg = $idGUIExit Then Exit
  120. DOWN_BY_LIST($list_file_url)
  121. ;按列表下载
  122. WEnd
  123. EndFunc ;==>start_job
  124. Func DOWN_BY_LIST($list_file_url)
  125. MsgBox($MB_SYSTEMMODAL, "网址", "开始下载列表里网址", 1)
  126. ;MsgBox($MB_SYSTEMMODAL, "", "开始下载列表里网址.")
  127. $FILE_HWN = FileOpen($list_file_url, 1)
  128. $size = _FileCountLines($list_file_url)
  129. If $list_file_url = "" Then
  130. MsgBox($MB_SYSTEMMODAL, "", "没有选择入口列表.现在退回")
  131. Return
  132. Else
  133. EndIf
  134. For $SIZES = $size To 1 Step -1
  135. ;
  136. $state = ""
  137. $line_url = FileReadLine($list_file_url, $SIZES)
  138. FileClose($line_url)
  139. ;ConsoleWrite("列表名称" & $line_url)
  140. If StringLen($line_url) > 10 Then
  141. ;to be continue
  142. $stock_id = StringTrimRight(StringTrimLeft("$line_url", 38), 5)
  143. ;+++++++++++++++++++++++++++++++
  144. $oIE.navigate($line_url)
  145. ;_ieloadwait($oIE)
  146. ;++++++++++++++++++++++++++
  147. ;ierw($line_url)
  148. ;sleep(500)
  149. Global $CURPID = 1
  150. pagereconize()
  151. set_stock_show()
  152. ;ending
  153. SetError(0)
  154. EndIf
  155. ;=========================================================
  156. _FileWriteToLine($list_file_url, $SIZES, "", True)
  157. FileClose($line_url)
  158. ;
  159. Next
  160. MsgBox($MB_SYSTEMMODAL, "", "已经提取完内容,右下任务栏选退出.")
  161. ;FileClose($FILE_HWN)
  162. Exit
  163. EndFunc ;==>DOWN_BY_LIST
  164. ;=================================================
  165. ;=====================================================================================
  166. Func ieobjint()
  167. ;$oIE.Navigate("http://baidu.com")
  168. $sURL = "http://guba.eastmoney.com/list,600382.html"
  169. Local $oEventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")
  170. If @error Then
  171. MsgBox($MB_OK, "有错误发生", _
  172. "ObjEvent: Can't use event interface 'DWebBrowserEvents'. Error code: " & Hex(@error, 8))
  173. EndIf
  174. With $oIE
  175. .Visible = 1
  176. .Top = (@DesktopHeight - 400) / 2
  177. .Height = 600 ; Make it a bit smaller than our GUI.
  178. .Width =400
  179. .Silent = 1 ; Don't show IE's dialog boxes
  180. Global $hIEWnd = HWnd(.hWnd) ; Remember the Window, in case user decides to close it
  181. EndWith
  182. EndFunc ;==>ieobjint
  183. ;======================================================================================
  184. Func removeIE()
  185. $oEventObject.Stop ; Tell IE we don't want to receive events.
  186. $oEventObject = 0 ; Kill the Event Object
  187. If WinExists($hIEWnd) Then $oIE.Quit ; Close IE Window
  188. $oIE = 0 ; Remove IE from memory (not really necessary).
  189. ;GUIDelete($hGUIMain) ; Remove GUI
  190. EndFunc ;==>removeIE
  191. Func set_stock_show()
  192. ;GUICtrlSetData($input1,$stock_id)
  193. EndFunc ;==>set_stock_show
  194. Func pagereconize()
  195. Local $Ele = @extended
  196. Sleep(1000)
  197. ;=====================hot============================
  198. ;SLEEP(300)
  199. Local $tags = @extended
  200. ;$tags = $oIE.document.GetElementsByTagName("div")
  201. instr($oIE)
  202. Local $text_s = _tc1($ie_all_span)
  203. Local $tmp = ""
  204. ;For $tag in $ie_all_span
  205. ; $class_value = $tag.GetAttribute("class")
  206. ; $class_value = $tag.classname
  207. ; If $class_value = "tc1" Then
  208. ; $tmp=$tag.innertext
  209. ; $text_s=$tmp&@CRLF&$text_s&@CRLF
  210. ;EndIf
  211. ;Next
  212. $TXTDATA = StringStripWS(HTML_Filters($text_s, 0), 8)
  213. FileWriteLine(@ScriptDir & "\data.txt",$line_url & " url/////")
  214. FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "hot /////")
  215. Local $TXTDATA = ""
  216. ;=======================tim==================
  217. ;SLEEP(300)
  218. Local $tags = @extended
  219. ;$tags = $oIE.document.GetElementsByTagName("DIV")
  220. Local $text_s = ""
  221. Local $tmp = ""
  222. ;For $tag in $tags
  223. For $tag In $ie_all_div
  224. ; $class_value = $tag.GetAttribute("class")
  225. $class_value = $tag.className
  226. If $class_value = "zwfbtime" Then
  227. $tmp = $tag.innertext
  228. $text_s = $tmp & @CRLF & $text_s & @CRLF
  229. EndIf
  230. Next
  231. $TXTDATA = StringStripWS(HTML_Filters($text_s, 0), 8)
  232. FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "time/////")
  233. Local $TXTDATA = ""
  234. ;====================bdy=============================
  235. ;SLEEP(300)
  236. Local $tags = @extended
  237. ;$tags = $oIE.document.GetElementsByTagName("DIV")
  238. Local $text_s = ""
  239. Local $tmp = ""
  240. ;For $tag in $tags
  241. For $tag In $ie_all_div
  242. ; $class_value = $tag.GetAttribute("class")
  243. $class_value = $tag.className
  244. If $class_value = "zwcontentmain" Then
  245. $tmp = $tag.innertext
  246. $text_s = $tmp & @CRLF & $text_s & @CRLF
  247. EndIf
  248. Next
  249. $TXTDATA = StringStripWS(HTML_Filters($text_s, 0), 8)
  250. FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "btbdy/////")
  251. ;==================================================================================================================================
  252. ; $text_s = _tl1($ie_all_div)
  253. ; FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "/////" & @CRLF & "--end1---" & @CRLF)
  254. ;============================================================================================================
  255. Local $TXTDATA = ""
  256. $reply_size = _sp1($ie_all_span)
  257. if $reply_size="" then
  258. $reply_size=0
  259. $TXTDATA=_tl1($ie_all_div)
  260. FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "end/////" & @CRLF & "-----" & @CRLF)
  261. GUICtrlSetData($input1 ,$TXTDATA)
  262. Else
  263. $reply_size=Number($reply_size)
  264. _getrpy($reply_size)
  265. ; MsgBox($MB_SYSTEMMODAL, "页数", $reply_size)
  266. EndIf
  267. ;MsgBox($MB_SYSTEMMODAL, "页数", $reply_size)
  268. EndFunc ;==>pagereconize
  269. func _getrpy($reply_size)
  270. $curfront = StringTrimRight($line_url, 5)
  271. For $rpt = 0 To $reply_size
  272. ;==========================================
  273. $nReply = $curfront & "_" & $rpt & ".html#storeply"
  274. ConsoleWrite($nReply & @CRLF)
  275. ierw($nReply)
  276. ;sleep(500)
  277. $CURPID = 2 ;set process to 2
  278. ;==============reconize=================
  279. ;=======================rpys==========================start
  280. ;SLEEP(300)
  281. ;Local $tags = @extended
  282. ; $tags = $oIE.document.GetElementsByTagName("DIV")
  283. Local $text_s = _tl1($ie_all_div)
  284. ;Local $tmp = ""
  285. ;For $tag In $ie_all_div
  286. ; $class_value = $tag.GetAttribute("class")
  287. ; $class_value = $tag.className
  288. ; If StringInStr($class_value,"zwlitext stockcodec") Then
  289. ConsoleWrite($text_s& @CRLF)
  290. ;EndIf
  291. ;Next
  292. ;$TXTDATA = StringStripWS(HTML_Filters($text_s, 0), 8)
  293. $TXTDATA =HTML_Filters($text_s, 0)
  294. ;WRITE CHECK URL
  295. FileWriteLine(@ScriptDir & "\data.txt", $TXTDATA & "end/////----" & @CRLF & "-----" & @CRLF)
  296. Local $TXTDATA = ""
  297. Next
  298. GUICtrlSetData($input1 ,$TXTDATA)
  299. ;endCollectt rply
  300. $data = "" ;restore data
  301. ;===============================================
  302. $CURPID = 0
  303. EndFunc
  304. Func _tc1($ie_all_span)
  305. Local $tmp = ""
  306. For $span In $ie_all_span
  307. If StringInStr($span.classname, "tc1") Then
  308. $tmp = $tmp & $span.innertext & "_"
  309. EndIf
  310. Next
  311. Return $tmp
  312. EndFunc ;==>_tc1
  313. Func instr($oIE)
  314. Global $ie_all_div = $oIE.document.GetElementsByTagName("DIV")
  315. Global $ie_all_span = $oIE.document.GetElementsByTagName("SPAN")
  316. EndFunc ;==>instr
  317. func _tl1($ie_all_div) ;数组中搜索标签
  318. local $tmp=""
  319. For $div IN $ie_all_div
  320. if StringInStr($div.className,"zwlitext stockcodec") then
  321. $tmp=$tmp&$div.innertext&"_"
  322. endif
  323. Next
  324. return $tmp
  325. endfunc
  326. Func _sp1($ie_all_span)
  327. Local $tmp = ""
  328. For $span In $ie_all_span
  329. If StringInStr($span.classname, "sumpage") Then
  330. $tmp =$span.innertext
  331. EndIf
  332. Next
  333. Return $tmp
  334. ;MsgBox($MB_SYSTEMMODAL, "标题", "元素在span.classname"&$tmp, 1)
  335. EndFunc ;==>