youtuber Posted October 4, 2017 Share Posted October 4, 2017 I cannot make Multi connections with winhttp Where am I making mistakes? expandcollapse popup#include <Array.au3> #include <String.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $ScriptDir = @ScriptDir If StringRight($ScriptDir, 1) <> "\" Then $ScriptDir &= "\" Global $aReadsFile = $ScriptDir & "UrlList.txt" FileDelete($aReadsFile) Global $aOpenFile = FileOpen($aReadsFile,1) $Form1 = GUICreate("Form1", 1231, 584) $Edit1 = GUICtrlCreateEdit("" & @CRLF, 16, 40, 401, 457, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2 = GUICtrlCreateEdit("", 432, 40, 240, 457) GUICtrlSetData(-1, "") $ButtonUrlCheck = GUICtrlCreateButton("Button URL Check", 16, 520, 107, 25) $CheckData = GUICtrlCreateButton("Check Data", 16, 552, 107, 25) $Edit3 = GUICtrlCreateEdit("" & @CRLF, 680, 40, 529, 457, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonUrlCheck $aGetNewComment = StringRegExp(MultipleConnections("https://www.autoitscript.com/forum/"), '<a\s*href=[\"](.*?)\?do\=getNewComment[\"].*?>',3) For $c = 0 To UBound($aGetNewComment) -1 FileWrite($aOpenFile, $aGetNewComment[$c] & @CRLF) Next $aOpenFile2 = FileOpen(@ScriptDir & '\UrlList.txt', 0) GUICtrlSetData($Edit1, FileRead($aOpenFile2)) FileClose($aOpenFile) Case $CheckData $aEditRead = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF,2) For $i = 0 To UBound($aEditRead) -1 $aGetConnectURL = MultipleConnections($aEditRead[$i]) GUICtrlSetData($Edit3, $aGetConnectURL & @CRLF,1) Next $aEditRead3 = StringSplit(StringStripCR(GUICtrlRead($Edit3)), @LF,2) $GetTheTopics = _StringBetween($aEditRead3, 'data-controller="core.front.core.lightboxedImages">','</div>') For $c = 0 To UBound($GetTheTopics) -1 GUICtrlSetData($Edit2, $GetTheTopics[$i] & @CRLF ,1) Next EndSwitch WEnd Func MultipleConnections($address) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oMyError = ObjEvent("AutoIt.Error", "httperror") $oHTTP.Open("GET", $address, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept", "*/*") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest") $oHTTP.SetRequestHeader("Referer", "https://www.autoitscript.com/forum/") $oHTTP.SetRequestHeader("Content-Length", "34") $oHTTP.SetRequestHeader("Connection", "keep-alive") $oHTTP.Send() If @error Then ConsoleWrite("Error connection") Else Local $sReceived = $oHTTP.ResponseText EndIf If $oHTTP.Status = 200 Then $oHTTP = Null Return $sReceived EndIf $oHTTP = Null Return -1 EndFunc Func httperror() ConsoleWrite("http error" & @CRLF) EndFunc Link to comment Share on other sites More sharing options...
ripdad Posted October 4, 2017 Share Posted October 4, 2017 expandcollapse popupFunc MultipleConnections($address); <-- Function can only make ONE SINGLE connection at a time. $oMyError = ObjEvent("AutoIt.Error", "httperror"); <-- this line needs to be near the top under #includes. Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", $address, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0") $oHTTP.SetRequestHeader("Accept", "*/*") $oHTTP.SetRequestHeader("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3") ; These are not needed for making a REQUEST ; ----------------------------------------- ;$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded"); <- not sending anything ;$oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest"); <- doubt this would help at all ;$oHTTP.SetRequestHeader("Referer", "https://www.autoitscript.com/forum/"); <- no need ;$oHTTP.SetRequestHeader("Content-Length", "34"); <- one length for all? not needed here ;$oHTTP.SetRequestHeader("Connection", "keep-alive"); <- not needed $oHTTP.Send() If @error Then ConsoleWrite("Error connection") $oHTTP = 0 Return SetError(1); <-- triggers an error. (code above function needs error checking) EndIf If $oHTTP.Status = 200 Then Local $sReceived = $oHTTP.ResponseText $oHTTP = Null; <-- use 0 instead Return $sReceived EndIf $oHTTP = Null; <-- use 0 instead Return -1 EndFunc Func httperror() ConsoleWrite("http error" & @CRLF) $oMyError.Clear; <-- clears the error Return SetError(1); <-- triggers an error EndFunc youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
youtuber Posted October 4, 2017 Author Share Posted October 4, 2017 There is a problem I can not get data from here Case $CheckData $aEditRead = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF,2) For $i = 0 To UBound($aEditRead) -1 $aGetConnectURL = MultipleConnections($aEditRead[$i]) GUICtrlSetData($Edit3, $aGetConnectURL & @CRLF,1) Next $aEditRead3 = StringSplit(StringStripCR(GUICtrlRead($Edit3)), @LF,2) $GetTheTopics = _StringBetween($aEditRead3, 'data-controller="core.front.core.lightboxedImages">','</div>') For $c = 0 To UBound($GetTheTopics) -1 GUICtrlSetData($Edit2, $GetTheTopics[$i] & @CRLF ,1) ;<--- The problem line Next Link to comment Share on other sites More sharing options...
ripdad Posted October 4, 2017 Share Posted October 4, 2017 You will have to provide UrlList.txt -- at least 2 or 3 url's in it. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
youtuber Posted October 4, 2017 Author Share Posted October 4, 2017 there is 17 url https://prnt.sc/gtaets Link to comment Share on other sites More sharing options...
ripdad Posted October 4, 2017 Share Posted October 4, 2017 Okay. I cannot do it right now. I have an appointment to go to. I will be back in about 2 hours. In the meantime, if someone else is available to help, that would be okay. Otherwise, I will help when I get back. youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Developers Jos Posted October 4, 2017 Developers Share Posted October 4, 2017 That is an image of the 17 urls, not the actual UrlList.txt file! Just attach the file to your post. Jos youtuber 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted October 4, 2017 Author Share Posted October 4, 2017 This is my file UrlList.txt Link to comment Share on other sites More sharing options...
ripdad Posted October 4, 2017 Share Posted October 4, 2017 I'm back. Not really sure what you want to accomplish. Do you want what members say in each post, or something else? Can you explain the outcome you expect? Be specific. --- See anything wrong in these 3 lines? $c and $i ? For $c = 0 To UBound($GetTheTopics) -1 GUICtrlSetData($Edit2, $GetTheTopics[$i] & @CRLF ,1) Next "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
youtuber Posted October 4, 2017 Author Share Posted October 4, 2017 Excuse me [$c] had to be, but I still can not get data $aEditRead3 = StringSplit(StringStripCR(GUICtrlRead($Edit3)), @LF,2) For $c = 0 To UBound($aEditRead3) -1 $GetTheTopics = _StringBetween($aEditRead3[$c], 'data-controller="core.front.core.lightboxedImages">','</div>') GUICtrlSetData($Edit2, $GetTheTopics & @CRLF ,1) Next Link to comment Share on other sites More sharing options...
ripdad Posted October 4, 2017 Share Posted October 4, 2017 That's because the source code of the webpage is broken with StringSplit(). So, it's fragmented and out of place for _StringBetween(), which is StringRegExp(). You cannot use StringSplit(). It will break the source every time. In addition, you might have to strip some characters from the source. $string = $strSourceCode $string = StringRegExpReplace($string, '(?s)[\r\n\t\v]', '') and then, strip the whitespace. $string = StringStripWS($string, 7) Then use _StringBetween(). --- You didn't answer my first and second question in post #9. youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
youtuber Posted October 4, 2017 Author Share Posted October 4, 2017 reply post #9 Data from $ Edit3 view-source:https://www.autoitscript.com/forum/topic/190621-winhttp-multilink-problem/ data-controller="core.front.core.lightboxedImages"> to get the source from </div> Link to comment Share on other sites More sharing options...
youtuber Posted October 5, 2017 Author Share Posted October 5, 2017 @ripdad I'm not exactly sure how? $aEditRead3 = GUICtrlRead($Edit3) $StringR = StringRegExpReplace($aEditRead3, '(?s)[\r\n\t\v]', '') $StringWS = StringStripWS($StringR, 7) $GetTheTopics = _StringBetween($StringWS, 'data-controller="core.front.core.lightboxedImages">','</div>') For $c = 0 To UBound($GetTheTopics) -1 GUICtrlSetData($Edit2, $GetTheTopics[$c] & @CRLF ,1) Next Link to comment Share on other sites More sharing options...
ripdad Posted October 5, 2017 Share Posted October 5, 2017 I will be busy for the next hour. Will be back after that. youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
ripdad Posted October 5, 2017 Share Posted October 5, 2017 This should work without the need for $Edit3... Case $CheckData Local $array = StringSplit(GUICtrlRead($Edit1), @CRLF, 1) Local $aData, $string For $i = 1 To $array[0] $string = MultipleConnections($array[$i]) If @error Then GUICtrlSetData($Edit2, 'Connection Error' & @CRLF, 1) ContinueLoop EndIf $string = StringRegExpReplace($string, '(?s)[\n\r\t\v]', '') $string = StringStripWS($string, 7) $aData = _StringBetween($string, 'data-controller="core.front.core.lightboxedImages">', '</div>') For $j = 0 To UBound($aData) - 1 GUICtrlSetData($Edit2, $aData[$j] & @CRLF, 1) Next Next EndSwitch If you do use $Edit3, you will have to increase its character limit and do one source at a time. You cannot add html sources on top of one another. It will cause you grief. $Edit3 = GUICtrlCreateEdit(..) GUICtrlSetLimit($Edit3, 500000) youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
youtuber Posted October 5, 2017 Author Share Posted October 5, 2017 Thank you for better information now I understand you I have another question Global $oMyError = ObjEvent("AutoIt.Error", "httperror"); <-- this line needs to be near the top under #includes. Is it more logical to add this line? global on top #include <Array.au3> #include <String.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $ScriptDir = @ScriptDir If StringRight($ScriptDir, 1) <> "\" Then $ScriptDir &= "\" Global $aReadsFile = $ScriptDir & "UrlList.txt" FileDelete($aReadsFile) Global $aOpenFile = FileOpen($aReadsFile,1) Global $oMyError = ObjEvent("AutoIt.Error", "httperror"); <-- this line needs to be near the top under #includes. $Form1 = GUICreate("Form1", 1231, 584) Link to comment Share on other sites More sharing options...
ripdad Posted October 5, 2017 Share Posted October 5, 2017 (edited) This would be a cleaner solution... #include <Array.au3> #include <String.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $oMyError = ObjEvent('AutoIt.Error', 'httperror') Global $sFile = @ScriptDir & '\UrlList.txt' Global $hFile = FileOpen($sFile, 2) Global $Form1 = GUICreate('Form1', 1231, 584) Opt('MustDeclareVars', 1) ensures that you declare all variables. It's good practice to use it. --edit-- corrected an error on second parameter of FileOpen() Edited October 5, 2017 by ripdad youtuber 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now