Page 1 of 1

Get string from other website

Posted: Sat Sep 04, 2010 5:37 pm
by tonchily
I'd like to know if it's possible to make strings generated on other websites appear on mine website as a string, I mean I'd echo 'em.

For example:

http://www.footstar.org/ver_jogador.asp?jog_id=44797
I'd like to have dribbling skill and number to appear on my website as "Dribbling: 20"

is it possible? If yes, I would really appreciate if you could post the full code. Thanks in advance.

Re: Get string from other website

Posted: Sat Sep 04, 2010 8:08 pm
by Jonah Bron
Unless they have an API, you'd have to do something called scraping. Scraping requires you to get the contents of that page with cURL or file_get_contents() (the latter is easier), and grab the part you want with the DOM or Regex (again, the latter is probably better overall).

The only problem is, they might not like the load it puts on their site. You should get permission first. And if the say yes, you should cache it out of common courtesy.

Re: Get string from other website

Posted: Sun Sep 05, 2010 5:29 am
by tonchily
Jonah Bron wrote:Unless they have an API, you'd have to do something called scraping. Scraping requires you to get the contents of that page with cURL or file_get_contents() (the latter is easier), and grab the part you want with the DOM or Regex (again, the latter is probably better overall).

The only problem is, they might not like the load it puts on their site. You should get permission first. And if the say yes, you should cache it out of common courtesy.
I've done the file_get_content(url) and echoed it out, and I do get the whole text (including that dribbling skill I want) but I don't know how to "crop" only that (guess that "cropping" method, if available, would be the easiest one)

Re: Get string from other website

Posted: Sun Sep 05, 2010 12:52 pm
by Jonah Bron
On the page you gave, the html around the dribble skill is this:

Code: Select all

<div class="">Dribbling</div></td>            <td width="5%">&nbsp;</td><td align="right">&nbsp;</td><td align="center" width="5%"><div class="skill_text"><div class="skill_">20</div></div>
If you don't know how to write regular expressions (regex), you should learn:

http://www.regular-expressions.info/tutorial.html
viewtopic.php?f=38&t=33147
viewtopic.php?f=38&t=40169

Re: Get string from other website

Posted: Sun Sep 05, 2010 3:38 pm
by tonchily
Jonah Bron wrote:On the page you gave, the html around the dribble skill is this:

Code: Select all

<div class="">Dribbling</div></td>            <td width="5%">&nbsp;</td><td align="right">&nbsp;</td><td align="center" width="5%"><div class="skill_text"><div class="skill_">20</div></div>
If you don't know how to write regular expressions (regex), you should learn:

http://www.regular-expressions.info/tutorial.html
viewtopic.php?f=38&t=33147
viewtopic.php?f=38&t=40169
I've read all that ages ago but I don't know how to define and get that number (because on other players profiles not all have dribbling 20 etc). I know on how to "get" the dribbling string, but I fail at getting that number. Can you show me a specific example?

Thanks