[已解决]请教GUI界面整合HTML代码获取功能后不能正常使用的原因
本帖最后由 riskstar 于 2014-7-29 07:50 编辑最近想写一个根据URL地址自动抽取对应的HTML页面的标题和内容的小工具,用于转帖。单独的GUI框架和HTML代码获取部分独立运行都没有问题,但是整合在一起就出现问题,烦请大家帮忙指点一下原因,谢谢!
示例地址:http://www.acfun.tv/a/ac1308779#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#Region ### START Koda GUI section ### Form=c:\source\gui\acfun文章获取.kxf
$Form1_1 = GUICreate("ACFUN文章获取器", 637, 456, 192, 124)
$Label1 = GUICtrlCreateLabel("URL地址:", 40, 16, 100, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Verdana")
$Input1 = GUICtrlCreateInput("", 144, 16, 425, 21)
$Edit1 = GUICtrlCreateEdit("", 40, 104, 529, 281)
;GUICtrlSetData(-1, "")
GUICtrlSetData($Edit1, "")
$Button1 = GUICtrlCreateButton("抓取", 56, 400, 75, 25)
$Button2 = GUICtrlCreateButton("复制标题", 448, 400, 75, 25)
$Button3 = GUICtrlCreateButton("复制内容", 192, 400, 75, 25)
$Button4 = GUICtrlCreateButton("清空", 320, 400, 75, 25)
$Label2 = GUICtrlCreateLabel("文章标题:", 40, 56, 100, 33)
GUICtrlSetFont(-1, 16, 400, 0, "Verdana")
$Input2 = GUICtrlCreateInput("", 144, 56, 425, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $nMsg = $Button1
$Url= GUICtrlRead($Input1)
Local $InetRead = InetRead($Url),$HTMLContents
If $InetRead <> "" Then $HTMLContents = BinaryToString($InetRead, 4)
$_Title = _StringBetween($HTMLContents, '<h2>', '</h2>')
$_Content= _StringBetween($HTMLContents, '<span class="clearfix"></span></div><div id="area-player"><p>', '<span class="clearfix"></span></div>')
GUICtrlSetData($Input2 , $_Title)
GUICtrlSetData($Edit1 , $_Content)
Case $nMsg = $Button2
$_Title = GUICtrlRead($Input2)
Case $nMsg = $Button3
$_Title = GUICtrlRead($Edit1)
Case $nMsg = $Button4
GUICtrlSetData($Input1, "")
GUICtrlSetData($Input2, "")
GUICtrlSetData($Edit1, "")
EndSwitch
WEnd
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#Region ### START Koda GUI section ### Form=c:\source\gui\acfun文章获取.kxf
$Form1_1 = GUICreate("ACFUN文章获取器", 637, 456, 192, 124)
$Label1 = GUICtrlCreateLabel("URL地址:", 40, 16, 100, 29)
GUICtrlSetFont(-1, 16, 400, 0, "Verdana")
$Input1 = GUICtrlCreateInput("", 144, 16, 425, 21)
$Edit1 = GUICtrlCreateEdit("", 40, 104, 529, 281)
;GUICtrlSetData(-1, "")
GUICtrlSetData($Edit1, "")
$Button1 = GUICtrlCreateButton("抓取", 56, 400, 75, 25)
$Button2 = GUICtrlCreateButton("复制标题", 448, 400, 75, 25)
$Button3 = GUICtrlCreateButton("复制内容", 192, 400, 75, 25)
$Button4 = GUICtrlCreateButton("清空", 320, 400, 75, 25)
$Label2 = GUICtrlCreateLabel("文章标题:", 40, 56, 100, 33)
GUICtrlSetFont(-1, 16, 400, 0, "Verdana")
$Input2 = GUICtrlCreateInput("", 144, 56, 425, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$Url= GUICtrlRead($Input1)
Local $InetRead = InetRead($Url),$HTMLContents
If $InetRead <> "" Then $HTMLContents = BinaryToString($InetRead, 4)
$_Title = _StringBetween($HTMLContents, '<h2>', '</h2>')
$_Content= _StringBetween($HTMLContents, '<span class="clearfix"></span></div><div id="area-player"><p>', '<span class="clearfix"></span></div>')
GUICtrlSetData($Input2 , $_Title)
GUICtrlSetData($Edit1 , $_Content)
Case $Button2
$_Title = GUICtrlRead($Input2)
Case $Button3
$_Title = GUICtrlRead($Edit1)
Case $Button4
GUICtrlSetData($Input1, "")
GUICtrlSetData($Input2, "")
GUICtrlSetData($Edit1, "")
EndSwitch
WEnd
回复 2# nmgwddj
谢谢 谢谢。。。学习力 学习,学习,感谢感谢
页:
[1]