ExtractLink

Web function.

The ExtractLink function returns all the links (HREF properties) of the child elements of the specified HTML element. Not available in WinTask Lite.

Usage

A Web table often contains elements that you need to click in order 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.

Syntax

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

Parameters

<HTML_descriptor>, string, HTML descriptor of the element from which all the links for its child elements are extracted.

tablink$(), array of strings. 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, numeric return code. When the extraction is successful, the function returns the number of links found, otherwise use this return code for Error Handling. The return code is -1 if the extraction could not be done.

Remarks

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

Use Spy tool to generate the HTML descriptor.

See also

CaptureTableHTML

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()

 

'Start the website now 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()