pushkar_nagle Posted May 31, 2016 Share Posted May 31, 2016 (edited) Hi, I would like to extract URLs from below HTML code: I am writing a script which automatically sends an email with URLs from the above code. Code I have written so far is: Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oTag = _IEFormElementGetObjByName($oForm, "ctl00$middleContentPlaceHolder$ctrlAssets$ctrlWebsites$websiteLoginView$cpeURLs_ClientState") Local $URL = _IEPropertyGet($oTag, "innertext") Edited October 2, 2017 by pushkar_nagle Link to comment Share on other sites More sharing options...
Jules Posted May 31, 2016 Share Posted May 31, 2016 You mean you want the URL of the current page displayed by your browser ? (in this case, Internet Explorer) If so, just use the built-in function _IEPropertyGet like this : _IEPropertyGet($oIE, "locationurl") where $oIE is your Internet Explorer object. That will return a String containing the URL of the page IE is currently displaying. Link to comment Share on other sites More sharing options...
pushkar_nagle Posted May 31, 2016 Author Share Posted May 31, 2016 No, I want URLs mentioned in href of above HTML code. Link to comment Share on other sites More sharing options...
AutoBert Posted May 31, 2016 Share Posted May 31, 2016 Use _StrinBetween: #include <String.au3> #include <Array.au3> Global $sMyFile = @ScriptDir & '\MyHtmlTest.html' $sText=FileRead($sMyFile) $aLinks=_StringBetween($sText,"a href='","'",$STR_ENDNOTSTART) $aLinks = _ArrayUnique($aLinks) _ArrayDisplay($aLinks) AlienStar 1 Link to comment Share on other sites More sharing options...
Jules Posted May 31, 2016 Share Posted May 31, 2016 Assuming all your href attributes belong to <a> tags, you can indeed use AutoBert's solution. There is also this solution that should work : ; Get a collection of all the <a> tags on the document Local $aTagsCollection = _IETagNameGetCollection($oIE, "a") ; Loop through those tags For $aTag In aTagsCollection ; You get the 'href' attribute $href = $aTag.href ; Then do whatever you want with the 'href' attribute ; ... Next Link to comment Share on other sites More sharing options...
AutoBert Posted May 31, 2016 Share Posted May 31, 2016 using the IE.au3 i suggest _IELinkGetCollection will be easiest solution. RickB75 1 Link to comment Share on other sites More sharing options...
pushkar_nagle Posted June 1, 2016 Author Share Posted June 1, 2016 Above codes are providing all the links in the document. I want Links from only the HTML code I have pasted above. Link to comment Share on other sites More sharing options...
AutoBert Posted June 1, 2016 Share Posted June 1, 2016 16 minutes ago, pushkar_nagle said: Above codes are providing all the links in the document. I want Links from only the HTML code I have pasted above. It provide all links you have in your html-snippet, but you have to tell him this: ; Open blank browser and insert a htmlsnipet, get link collection ; loop through items and display the associated link URL references #include <IE.au3> #include <MsgBoxConstants.au3> $sSnipet=FileRead('HTML.txt') $oIE=_IECreate() _IEBodyWriteHTML($oIE,$sSnipet) ConsoleWrite('_IEBodyWriteHTML error: '&@error&' extended: '&@extended&@CRLF) $oLinks = _IELinkGetCollection($oIE) $iNumLinks = @extended $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF For $oLink In $oLinks $sTxt &= $oLink.href & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt) _IEQuit($oIE) the file html.txt contains your HTML code I have pasted above. Link to comment Share on other sites More sharing options...
pushkar_nagle Posted June 1, 2016 Author Share Posted June 1, 2016 (edited) Apologies, if I am not clear enough. HTML code I pasted above is a part of a document which contains many links. But I want links that exist under table ID 'ctl00_middleContentPlaceHolder_ctrlAssets_ctrlWebsites_websiteLoginView_grdURLs'. I have written a code below to get all table tags and then selecting above particular tag. Then it will get 'a' tags from this table and will display links. But its not giving any output. Is this the correct way? Edited October 2, 2017 by pushkar_nagle Link to comment Share on other sites More sharing options...
AutoBert Posted June 1, 2016 Share Posted June 1, 2016 as there is only a placeholder for future urls, you have to trigger the event filling the placeholder with real urls. Therefore the URL or at least the complete source of the site to automate is needed. Link to comment Share on other sites More sharing options...
pushkar_nagle Posted June 1, 2016 Author Share Posted June 1, 2016 (edited) Attached complete source of the page. Edited October 2, 2017 by pushkar_nagle 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