Imranimi Posted March 4, 2019 Author Share Posted March 4, 2019 (edited) expandcollapse popup#include <IE.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <ArrayDisplayInternals.au3> #include <InetConstants.au3> #include <WinAPI.au3> #include <WinAPIsysinfoConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Misc.au3> #include <Inet.au3> #include <File.au3> #include <Date.au3> #include <Misc.au3> #include <Debug.au3> Local $ProductName Local Const $ie_newtab = 0x0800 Local $arr[30] $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A") _IELoadWait($oIE, 1, 1) $sHtmlpag = _IEBodyReadHTML($oIE) Local $oInputs = _IETagNameGetCollection($oIE, "a") Local $array = StringRegExp($sHtmlpag, "More information", $STR_REGEXPARRAYGLOBALMATCH) MsgBox($MB_SYSTEMMODAL, "Product Name", $array) _ArrayDisplay($array) For $i=0 To UBound ($array) -1 For $oInput In $oInputs if $oInput.title = "More information" then Local $oIELink = $oInputs $oIE.Navigate($oinput.href, $ie_newtab) MsgBox($MB_SYSTEMMODAL, "Product Name", $oinput.href) _IELoadWait($oIE) ExitLoop endif Next MsgBox($MB_SYSTEMMODAL, "Chains and Accessories", $oIELink.title) Send("^w") Sleep(3000) Next Func Terminate() Exit 0 EndFunc ;==>Terminate @faustf, Bundle of thanks for diverting me to on ARRAY, in the above shared code please note that it is showing all the hyperlinks with Title ="More information" collected in the array & only one first array is opening in new tab. after closing the tab the script is terminated and the script next to second-loop is not working. <a title="More information" href="productinfo.htm?orgid=WKTL 150">WKTL 150</a> <img style="vertical-align: middle;" src="images/information38.png"> ----------> this image is also have title = "More Information" Above code is displaying me the both <a> & <img> in array but i need to work only on <a> I need to open & close all the href's one by one (other process for what to do with the opened tabs.... I have already completed that script) Edited March 4, 2019 by Imranimi Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 4, 2019 Share Posted March 4, 2019 (edited) 32 minutes ago, Imranimi said: only one first array is opening in new tab. Spoiler Things that the user may find unpleasant: Spoiler Open your eyes. Remove ExitLoop from the Loop then. 32 minutes ago, Imranimi said: Above code is displaying me the both <a> & <img> in array but i need to work only on <a> Exclude img tags from your search loop. Spoiler Things that the user may find unpleasant: Spoiler This is because you're copy-pasting/asking for code since you're here and you'll never understand what your code does. Edited March 4, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
faustf Posted March 4, 2019 Share Posted March 4, 2019 Local $array = StringRegExp($sHtmlpag, "More information", $STR_REGEXPARRAYGLOBALMATCH) try Local $array = StringRegExp($sHtmlpag, '<a title="More information" href="(.*?)"> WKTL 150 </a>', $STR_REGEXPARRAYGLOBALMATCH) Imranimi 1 Link to comment Share on other sites More sharing options...
faustf Posted March 4, 2019 Share Posted March 4, 2019 (edited) 6 hours ago, FrancescoDiMuro said: Reveal hidden contents Things that the user may find unpleasant: Reveal hidden contents Open your eyes. Remove ExitLoop from the Loop then. Exclude img tags from your search loop. Reveal hidden contents Things that the user may find unpleasant: Reveal hidden contents This is because you're copy-pasting/asking for code since you're here and you'll never understand what your code does. Remove ExitLoop from the Loop then. Edited March 4, 2019 by faustf Link to comment Share on other sites More sharing options...
Imranimi Posted March 5, 2019 Author Share Posted March 5, 2019 (edited) @faustf Thanks for your pleasant feedback & pushing me to finish my script with all requirement (Oh thanks for the hidden comments, it really helped me to examine/see my script carefully) Can you give me a hint to filter img-tag in search loop. Really, you had helped me alot to close my script, Thanks a lot Edited March 5, 2019 by Imranimi Link to comment Share on other sites More sharing options...
Imranimi Posted March 5, 2019 Author Share Posted March 5, 2019 @faustf I tried with the below but didn't succeeded Local $array = StringRegExp($sHtmlpag, '<a title="More information" href="(.*?)"> "(.*?)" </a>' $STR_REGEXPARRAYGLOBALMATCH) Link to comment Share on other sites More sharing options...
faustf Posted March 5, 2019 Share Posted March 5, 2019 (edited) your regexp is modify, this part probably not match nothing "(.*?)" </a>' because " " in your html suppose not exist because if you want catch wktl 150 simply (.*?) WKTL 150 </a>', i spoken use regexp buddy and find a correct regexp for your case is difficult for me help without a webpage ...try Edited March 5, 2019 by faustf Imranimi 1 Link to comment Share on other sites More sharing options...
Subz Posted March 5, 2019 Share Posted March 5, 2019 What is the point of the array? Its not used at all in the script posted above except for a loop? If you wanted to capture the urls into an array you would just use the objects href as below: #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A") _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then $oIE.Navigate($oLink.href, $ie_newtab) _IELoadWait($oIE) _ArrayAdd($aMoreInfo, $oLink.href) EndIf Next EndIf _ArrayDisplay($aMoreInfo) Imranimi 1 Link to comment Share on other sites More sharing options...
Imranimi Posted March 6, 2019 Author Share Posted March 6, 2019 7 hours ago, Subz said: What is the point of the array? Its not used at all in the script posted above except for a loop? If you wanted to capture the urls into an array you would just use the objects href as below: #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A") _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then $oIE.Navigate($oLink.href, $ie_newtab) _IELoadWait($oIE) _ArrayAdd($aMoreInfo, $oLink.href) EndIf Next EndIf _ArrayDisplay($aMoreInfo) Thanks a Ton but results are same for me as its showing url of both <a> & <img> I need to filter one & play with it i am doing r&d & will share the solution soon, if you have any idea just let me know. Link to comment Share on other sites More sharing options...
Imranimi Posted March 6, 2019 Author Share Posted March 6, 2019 8 hours ago, faustf said: your regexp is modify, this part probably not match nothing "(.*?)" </a>' because " " in your html suppose not exist because if you want catch wktl 150 simply (.*?) WKTL 150 </a>', i spoken use regexp buddy and find a correct regexp for your case is difficult for me help without a webpage ...try I am trying to match & filter my required <a> Link to comment Share on other sites More sharing options...
Imranimi Posted March 6, 2019 Author Share Posted March 6, 2019 One & Last thing for this thread, Please provide some hint & help to solve. How can i pick only one link when they are in array, as per guide by @faustf 1. Hypertext-Link 2. Image-Link @Subz your code is also give me the same result. For explanation: The above links are of same product & in _ArrayDisplay() its showing me 2 products. How can i play with only one link. below is the script-line which i am using ARRAY. ... .... ..... $sHtmlpag = _IEBodyReadHTML($oIE) Local $oInputs = _IETagNameGetCollection($oIE, "a") Local $array = StringRegExp($sHtmlpag, "More information", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($array) ... .... ..... Autoit-Help Forum Guys are very much helpful & loving, they helped me a lot to complete my script (as i am a new bee). Just show me a right way to solve above situation. @Nine @faustf @Subz Thanks a ton, Cheers Link to comment Share on other sites More sharing options...
Subz Posted March 6, 2019 Share Posted March 6, 2019 You just need to check the next tagname, the following will only navigate and add links to the array where the next tagname doesn't match <img...> tag. #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A", 1) _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then ;~ Check to see if next element is an <img...> tag If $oLink.NextElementSibling.tagName <> "img" Then $oIE.Navigate($oLink.href, $ie_newtab) _IELoadWait($oIE) _ArrayAdd($aMoreInfo, $oLink.href) EndIf EndIf Next EndIf _ArrayDisplay($aMoreInfo) Imranimi 1 Link to comment Share on other sites More sharing options...
Imranimi Posted March 6, 2019 Author Share Posted March 6, 2019 ;~ Check to see if next element is an <img...> tag If $oLink.NextElementSibling.tagName <> "img" Then The above code is not working as per my requirement & it's giving the same previous results..... ... (no change in result) Link to comment Share on other sites More sharing options...
Imranimi Posted March 7, 2019 Author Share Posted March 7, 2019 any further suggestions or idea to differentiate between the above mentioned tags.... ... Link to comment Share on other sites More sharing options...
Subz Posted March 7, 2019 Share Posted March 7, 2019 Are you just using the code as posted? It works fine for me. Link to comment Share on other sites More sharing options...
Imranimi Posted March 7, 2019 Author Share Posted March 7, 2019 (edited) no, i am modifying it because i need to open the tabs one-by-one after pop-up message as your code is directly opening the tabs in one shot & making my PC & internet too much busy so now i am adding message-box script to give a break in loop. Edited March 7, 2019 by Imranimi Link to comment Share on other sites More sharing options...
Subz Posted March 7, 2019 Share Posted March 7, 2019 Then just use the following to get the array: #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A", 1) _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then ;~ Check to see if next element is an <img...> tag If $oLink.NextElementSibling.tagName <> "img" Then _ArrayAdd($aMoreInfo, $oLink.href) EndIf EndIf Next EndIf _ArrayDisplay($aMoreInfo) Link to comment Share on other sites More sharing options...
Imranimi Posted March 7, 2019 Author Share Posted March 7, 2019 yes, the results are same.... showing 908-items in array but actually they are half to this number (454-items) as in array they are coming in duplicate because the <a> & <img> links share before. How can i bypass or filter 1st-array to 3rd then 5th because it will save my time otherwise i have do one task for twice ..... Urgent help needed, thanks.... Link to comment Share on other sites More sharing options...
Subz Posted March 7, 2019 Share Posted March 7, 2019 (edited) Don't know why it's not working for you, but you can either use: a. _ArrayUnique, to only show unique results (example in the code below. Or b. Just add unique links only #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A", 1) _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then If _ArraySearch($aMoreInfo, $oLink.href) = -1 Then _ArrayAdd($aMoreInfo, $oLink.href) EndIf Next EndIf _ArrayDisplay($aMoreInfo) ;~ Local $aUniqueLinks = _ArrayUnique($aMoreInfo) ;~ _ArrayDisplay($aUniqueLinks) Edited March 7, 2019 by Subz Fr33b0w and Imranimi 1 1 Link to comment Share on other sites More sharing options...
Imranimi Posted March 10, 2019 Author Share Posted March 10, 2019 Thanks a lot @Subz, i got my requirement in your recent shared script. Cheeeeers.... 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