Jump to content

Recommended Posts

Posted

Hi,

I am trying to get product names and links from a website, but having trouble with the code:

#include <IE.au3>
$oIE = _IECreate("http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=towel&x=0&y=0")  ;open a webpage in IE
$sText = _IEBodyReadHTML ($oIE)

;-----------------Find product links and display them---------------
#include <String.au3>
#include <Array.au3>
$product = _StringBetween($sText, '<a class="title" href="', '">')
_ArrayDisplay($product, 'Default Search')

The problem is, in this case, I suppose I should be getting all the product links, with the first product link (link for Pike Street 725) in the first row, the second one in the second row, and so on. However, I only got three irrelevant product links. Is it because I didn’t get the page source correctly? I have no idea. Can someone help me figure it out, how to fix the problem?

Many thanks!

Posted (edited)

@PsaltyDS

Thanks, the problem has been solved. I use _IELinkGetCollection()to get specific links, then use other methods to sort out duplicate links.

Here is the revised code:

#include <IE.au3> 
#Include <Array.au3>  
$oIE = _IECreate("http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=towel&x=0&y=0")  ;open a webpage in IE  
$oLinks = _IELinkGetCollection ($oIE) 
$iNumLinks = @extended Global 
$Link_Array[$iNumLinks] 
For $oLink In $oLinks     
    If StringInStr($oLink.href,"?ie=UTF8&qid=") Then        
        _ArrayAdd($Link_Array,$oLink.href)  
    EndIf      
Next _ArrayDisplay($Link_Array)
Edited by jxn

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...