Extracting an Html Link

Questions and answers about anything related to Helium Scraper
Post Reply
loneranger
Posts: 1
Joined: Thu Aug 09, 2012 6:03 am

Extracting an Html Link

Post by loneranger » Thu Aug 09, 2012 6:14 am

Hi, a site I am trying to scrape has an external link to another website with javascript:void(0). I need to scrape the actual external link.

The code on the site is below and I would need to scrape the http://www.xyz.com out of this java script. Is that possible with Helium and if so can some one show me how?

Thanks in advance!

Code: Select all

<div class="sponsorbanner"><script type="text/javascript" language="javascript"> 
	var browName = navigator.appName; 
	var SiteID = 1; 
	var ZoneID = 385; 
	var siteUrl ='http://banner.thissiteurl.com/'; 
	var browDateTime = (new Date()).getTime(); 
	if (browName=='Netscape') 
	{ 
	document.write('<s'+'cript lang' + 'uage="jav' + 'ascript" src="' + siteUrl + 'a.aspx?ZoneID=' + ZoneID + '&Task=Get&IFR=False&Browser=NETSCAPE4&PageID=89304&SiteID=' + SiteID + '&Random=' + browDateTime + '">'); document.write('</'+'scr'+'ipt>'); 
	} 
	else 
	{ 
	document.write('<s'+'cript lang' + 'uage="jav' + 'ascript" src="' + siteUrl + 'a.aspx?ZoneID=' + ZoneID + '&Task=Get&IFR=False&PageID=89304&SiteID=' + SiteID + '&Random=' + browDateTime + '">'); document.write('</'+'scr'+'ipt>'); 
	} 
	</script> 
	</div> 
	<div id="ContentPlaceHolder1_UpdatePanel"> 
	
	<div class="locatorleftsubleftcolumn"> 
	<div class="bold12px"><a href="javascript:void(0)" rel="nofollow" onclick="javascript:window.open('http://www.xyz.com',StoreWebsite'); " >XYZ Store&nbsp;<img src="http://images.thissiteurl.com.com/ newwindow_icon.gif" width="16" height="13" alt="Go to XYZ Website" /></a></div> 

webmaster
Site Admin
Posts: 521
Joined: Mon Dec 06, 2010 8:39 am
Contact:

Re: Extracting an Html Link

Post by webmaster » Sat Aug 11, 2012 12:53 am

Try creating a JavaScript gatherer with this code:

Code: Select all

try
{
	var url = "";
	function getUrl(param1) { url = param1; }
	var func = element.getAttribute("onclick").toString();
	var body = func.substring(func.indexOf("{") + 1, func.lastIndexOf("}")).replace("window.open", "getUrl");
	eval(body);
	return url;
}
catch(error)
{
	return error.message;
}
Say you call it OnClickURL. Then you'd create a kind that selects the A element (the one that has the onclick attribute) and extract the JS_OnClickURL property of this kind. To make sure it works, before performing any extraction, click on the Choose visible properties button in the selection panel and select the JS_OnClickURL, and then select one of these links (if the DIV that contains it gets selected instead, you can play with the Select first child and Select next sibling buttons until the A element is selected.
Juan Soldi
The Helium Scraper Team

Post Reply