页面识别.乱码au3 11 KB

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