views:

35

answers:

1

OK So, I'm learning/using xpath for a basic application that's effectively ripping data off another website.

I need to gain the knowledge of each persons Country/Suburb/area.
In some instances you can get Australia/Victoria/Melbourne for instance.
Others may just be Australia/Melbourne.
Or even just Melbourne OR just Australia.

So I'm current able to view the below code and rip all of the information with the string xpath //table/tr/td/table/tr/td/font/a. This returns every entry, but what I really want is to group each lot separately.

I hope someone out there on planet earth knows what I just tried to explain... and can help...

Good day!

The source document contains data like this:

<tr>
    <td>
        <font face="arial" size="2">  
            <strong>Location:</strong>
            <a href="http://maps.google.com/maps?q=Australia" target="mapblast" style="text-decoration:none">Australia</a>,
            <a href='http://maps.google.com/maps?q=Australia%20Victoria'target="mapblast" style='text-decoration:none'>Victoria</a>, 
            <a href='http://maps.google.com/maps?q=Australia%20Melbourne%20Victoria'target="mapblast" style='text-decoration:none'>Melbourne</a>
        </font>
    </td>
</tr>
+1  A: 

To find each person's record, the XPath query is //table/tr/td/table/tr/td/font, or you could use //td/font[strong = 'Location:']. This will return a collection containing 1 element for each person.

To find the a elements under a particular font you could use XPath a from the font. This can also be done by iterating the children collection of the element.

Lachlan Roche