Jump to content

How can I get URLs from HTML page?


Recommended Posts

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 by pushkar_nagle
Link to comment
Share on other sites

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

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

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

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 by pushkar_nagle
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...