Home > Language Reference > Web Functions > ExtractLink

ExtractLink

The ExtractLink function returns all the links (HREF property) of the child elements of the specified HTML element.

Usage

A web table often contains elements that you need to click to display and capture the details of each item in the table. As the elements displayed within the table are dynamic, you cannot know by advance the link name for each link to click. ExtractLink function returns each link name listed under the specified element and then you can use the link name as the argument for Navigate function and so navigate to the detailed page for each child element.

Video: In many automation web processes, you need to click every Product name/ads/... displayed in a web table in order to display each Product/ad/... details page. WinTask x64 ExtractLink function retrieves dynamically all the links and this video shows how it can be used in a loop.

Syntax

ret=ExtractLink(<html_descriptor>, tablink$())

Parameters

<html_descriptor>, string, HTML descriptor of the HTML table element to capture. Use Spy tool for generating the <HTML_descriptor> parameter.

tablink$(), array of strings, extracted links. The array must be declared at the beginning of the script using Dim. The link (HREF property) for each child element is returned in this array, beginning with index 0. If the array is smaller than the range, only the number of links which fit in the array are written.

Return value

Ret, optional numeric return code. If the function succeeds, the return value is the number of extracted links. If the function fails, the return value is a negative value (see Web Functions Error Codes).

Remarks

ExtractLink does not include any synchronization; a UsePage must be used before to be sure that the element is ready.

See also

CaptureTableHTML
Navigate

Examples

'On a web page displaying a list of companies,
'we need to click each company name and capture some data on the detailed page of each company

'Declare the array for the capture process
Dim contact$(10)
'Declare the array for ExtractLink function
Dim link$(100)

'Start the website
StartBrowser("IE","
http://www.actuary.com/actuarial-recruiters/")

UsePage("Actuarial Recruiters Directory from Actuary.com - Actuary Recruiters and Actuarial Recruiters for Actuarial Jobs in Actuarial Directory")
'Extract all the links which are under the TABLE titled Directory of Actuarial Recruiters
ret = ExtractLink("TABLE[CONTENT='Directory of Actuarial Recruiters']", link$())
'display how many links have been found
msgbox(ret)

'loop to navigate to each page listed in link$() array.
i=0
repeat
    Navigate(link$(i))
    UsePage("Actuarial Recruiter Directory Listing of Actuarial Careers, Inc.® from Actuary.com")
    'On the new page, capture some data
    ret = CaptureTableHTML("TABLE[CONTENT='Contact:']", "R3C1:R3C1", contact$())
    'display them for a check. The data can be written to an Excel file.
     msgbox(contact$(0))
     i=i+1
     'We stop the loop at ret-1 because the last link retrieved by ExtractLink is the link
     'Click here to see how to list your company (this link is part of the TABLE).
until i=ret-1

CloseBrowser()

 



'On a web page displaying a list of companies loaded in Firefox,
'we need to click each company name and capture some data on the detailed page of each company

'Declare the array for the capture process
Dim contact$(10)
'Declare the array for ExtractLink function
Dim link$(100)

'Start the website using Firefox
StartBrowser("FF","
http://www.actuary.com/actuarial-recruiters/")

UsePage("Actuarial Recruiters Directory from Actuary.com - Actuary Recruiters and Actuarial Recruiters for Actuarial Jobs in Actuarial Directory")
'Extract all the links which are under the TABLE titled Directory of Actuarial Recruiters
ret = ExtractLink("TABLE[CONTENT='Directory of Actuarial Recruiters']", link$())
'display how many links have been found
msgbox(ret)

'loop to navigate to each page listed in link$() array.
i=0
repeat
    Navigate(link$(i))
    UsePage("Actuarial Recruiter Directory Listing of Actuarial Careers, Inc.® from Actuary.com")
    'On the new page, capture some data
    ret = CaptureTableHTML("TABLE[CONTENT='Contact:']", "R3C1:R3C1", contact$())
    'display them for a check. The data can be written to an Excel file.
     msgbox(contact$(0))
     i=i+1
     'We stop the loop at ret-1 because the last link retrieved by ExtractLink is the link
     'Click here to see how to list your company (this link is part of the TABLE).
until i=ret-1

CloseBrowser()