0

I would like to extract data from a website, whose code is written like this:

...
<tr>
  <td class="something1"><a class="whatever" href="#">NAME</a>&nbsp;</td>
  <td class="something2">DATA</td>
  <td class="something3">NUMERIC DATA</td>
</tr>
...

In particular, I have my NAME list from my MySQL database, and if my NAME is equal to NAME on this website, I want to print on my website the correspondent NUMERIC DATA. I know I can do something with php_simple_html_dom but I cannot really achieve this action. Can you please help me?

Thanks!

Sfrow
  • 381
  • 1
  • 2
  • 15
  • 1. cURl request to get the HTML from the page. 2. load the returned document into a `DOMDocument`, 3. iterate each row, 4. compare the text of the a element within the td with a class of something1 against the result of the sql query. – Ohgodwhy Sep 13 '14 at 19:02

1 Answers1

0

So you want to read NAME first. if relevant then read the rest? You can read a website Dom as explained here: How do I get the HTML code of a web page in PHP?

$html = file_get_contents('http://pathToTheWebsite.com/thePage');

Now lets parse the $html with some regex. (you can use that library too, the documentation tells you how to do it!

preg_match('/<td class="something1"><a class="whatever" href="#">(?<name>\w)</a>&nbsp;</td>/', $html, $matches);

now $matches['name'] will contain the NAME. You can do the same for the rest and maybe cleanup that regex a little this was just an example.

Community
  • 1
  • 1
Arijoon
  • 2,184
  • 3
  • 24
  • 32