XPATH nested Tag is not working

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
User avatar
rajtak
Posts: 26
Joined: Mon May 11, 2009 3:57 am
Contact:

XPATH nested Tag is not working

Post by rajtak » Wed May 04, 2016 4:00 am

Hello,

Code: Select all

<div class="product-thumbnails" data-show="5"><div href="http://cdn.palmgren.com/images/products/9661051.jpg" class="item-image" title=""><img width="100" height="128" src="http://cdn.palmgren.com/images/thumbnails/9661051.jpg" alt=""/></div><div href="http://cdn.palmgren.com/images/products/9661101_death_stop.jpg" class="item-image" title=""><img width="100" height="128" src="" alt=""/></div></div>			</div>
I have written the code below to extract src i.e. http://cdn.palmgren.com/images/thumbnails/9661051.jpg but it is not working. please help me to correct the code.

Code: Select all

TAG XPATH="//div[@class="product-thumbnails"]/div[1]/img" EXTRACT=src

Thanks
Thanks,
Raj
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: XPATH nested Tag is not working

Post by Trax » Wed May 04, 2016 12:58 pm

I feel like I'm starting to sound like a broken record on this forum, I keep repeating the words javascript & jQuery:


script.js

Code: Select all

function loadJQ() { // Load Jquery
	function loadScriptFromURL(url) {
		var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
		async = false;
		request.open('GET', url, async);
		request.send();
		if (request.status !== 200) {
			var message = 'An error occurred while loading script at url: ' + url + ', status: ' + request.status;
			iimDisplay(message);
			return false;
		}
		eval(request.response);
		return true;
	}
	loadScriptFromURL('https://www.dropbox.com/s/47cj0fqxnsijm2n/jquery-2.2.2.min.js?raw=1');
	$ = window.$,
	JQuery = window.JQuery;
}

function iWait(waitTime) {
	iimPlayCode('WAIT SECONDS =' + waitTime);
}

loadJQ()

alert($('.item-image img').attr('src'))

Tested on :
Windows 7
jQuery 2.2.2
Firefox/Mozilla 46
iMacros 8.9.7
User avatar
rajtak
Posts: 26
Joined: Mon May 11, 2009 3:57 am
Contact:

Re: XPATH nested Tag is not working

Post by rajtak » Thu May 12, 2016 8:00 am

I have figured it out

just replaced the =src with =HREF at the end and it worked.

TAG XPATH="//div[@class="product-thumbnails"]/div[1]/img" EXTRACT=HREF
Thanks,
Raj
chivracq
Posts: 8722
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: XPATH nested Tag is not working

Post by chivracq » Thu May 12, 2016 3:05 pm

rajtak wrote:I have figured it out

just replaced the =src with =HREF at the end and it worked.

Code: Select all

TAG XPATH="//div[@class="product-thumbnails"]/div[1]/img" EXTRACT=HREF
Hum..., very good...! And Thanks for sharing. That was indeed exactly my idea when you had opened your Thread, but I didn't react as you had not mentioned your FCI (Required Info when you open a Thread...), and the Syntax you were trying to use might (...?) have worked indeed, but only on the iMB (iMacros Browser) which supports Custom Attributes for 'EXTRACT'. (Not supported on FF or CR which is probably your Config...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
backcao
Posts: 6
Joined: Fri Jun 10, 2016 7:36 pm

Re: XPATH nested Tag is not working

Post by backcao » Fri Jun 10, 2016 8:05 pm

rajtak wrote:I have figured it out

just replaced the =src with =HREF at the end and it worked.

TAG XPATH="//div[@class="product-thumbnails"]/div[1]/img" EXTRACT=HREF
Bravo
Post Reply