Scrape Attribute
(→Example 2: Scraping with Regular Expressions) |
|||
Line 41: | Line 41: | ||
− | [[File:scregex. | + | [[File:scregex.gif]] |
Revision as of 01:12, 8 June 2014
$Scrape Attribute is a Browser Function.
The function returns the value of a specified element on a selected element. As with all other scraping, you will be scraping the data to a list or variable.
The Element Selector is used to select an item for the scrape attribute.
Element To Scrape: The element on the page selected for scraping
Attribute To Scrape: The attribute of the selected page element that is going to be scraped (for example, the innerhtml)
Example 1
set(#my item, $scrape attribute(<href="/files/ScriptReferences//TheSelectors.pdf">, "name"), "Global")
Running the script sets a variable named "my item". The scrape attribute scrapes the selected element by the innertext. If the innertext of the item is available on the page, the innertext is scraped to the variable, as seen in the debugger.
add list to list(%my list, $scrape attribute(<href=w"/files/ScriptReferences/*.pdf">, "innertext"), "Delete", "Global")
This script will scrape all attributes that meet the wildcard criteria by their innertext.
All scraped items are placed in a list and each one is treated as an individual list item.
Example 2: Scraping with Regular Expressions
To use Regex to find an element on a webpage for scraping, simply click the Advanced Editor option, select the attribute the Regex will be matching and click the Exact Match drop down to select the Regular Expressions option.
navigate("http://listofrandomnames.com/index.cfm?generated", "Wait") wait(3) click(<type="submit">, "Left Click", "No") wait(3) set(#blue, $scrape attribute(<innertext=r"^(?<FirstName>\\w+)\\s(?<LastName>\\w+)$">, "innertext"), "Global")
Running the script produces the following list of random names:
More Tools Alden Gero Deanna Badillo Earlean Schulman Kimberley Maney Treva Belnap Sharon Kempker Shemika Anderton Cleopatra Eberhardt Zenobia Molloy Sherell Vanepps Jenette Belfiore Rosamond Boyden Jama Pless Delma Brightwell Scot Elswick Ivy Peed Melodie Cendejas Fernande Wimmer Stephine Twiggs Ashlea Strasburg Lorem Ipsum Joe Apple