0

I'm trying to learn about scraping information from a website for iOS and I'm using a website of a local radio station to practice. I have tried by best to figure out the Xpath needed to present the information within the tags in a table. The HTML is as follows (there are many more table rows, this is just the first one).

EDIT

<form action="http://www.someurl.ie/index.php/news" method="post" name="adminForm" id="adminForm">
<table class="category">
    <tbody>
        <tr class="cat-list-row0" >

            <td class="list-title">
                <a href="/index.php/news/some-news-story-here">
                        some news story here</a>
                    </td>
                        </tr>

This is the path that I have come up with but it hasn't worked for me. Could anyone direct me as to what I'm doing wrong/missing with this?

@"//div[@class='cat-items']/form[@id=adminForm]/@action/table[@class='category']/tbody/tr[@class='cat-list-row']/td[@class='list-title']/a"])
<div class="cat-items">

If anyone could help or point me in the direction of help I would be very grateful. Thanks!

Onion
  • 11
  • 6
  • Can only assume up to /form, would have expected /form[@id='adminForm']. Start from //div. if that works add more specifiers, until it goes wrong on you. – Tony Hopkinson Dec 15 '13 at 23:34
  • Have a look at the source code (using "view source code", not Firebug/Chrome Developer Tools). Does the table really contain `` elements? Compare http://stackoverflow.com/questions/18241029/why-does-my-xpath-query-scraping-html-tables-only-work-in-firebug-but-not-the. Also: Please include all relevant code, this includes the div you're querying (but Tony is right on better starting at the form having the id attribute). And if cutting HTML, do not omit the closing HTML tags, makes testing against the example input much much harder. – Jens Erat Dec 16 '13 at 01:04

1 Answers1

0

There are three problems in your XPath expression:

  1. The <form/> id 'adminForm' is unquoted
  2. The attribute @action is a path step in the middle of the expression
  3. The <tr/> class 'cat-list-row0' is missing the zero.

The corrected expression:

@"//div[@class='cat-items']/form[@id='adminForm']/table[@class='category']/tbody/tr[@class='cat-list-row0']/td[@class='list-title']/a"
joemfb
  • 3,056
  • 20
  • 19