Scrape website to retrieve certain li elements

Go To StackoverFlow.com

0

I'm running a lottery syndicate and want to automate our system to check for the lottery numbers (UK National Lottery)

The url I am getting is: https://www.national-lottery.co.uk/player/p/results/lotto.ftl

and I am using

<?php
$html = file_get_contents("https://www.national-lottery.co.uk/player/p/results/lotto.ftl");
?>

I would like to be able to grab this area of the page, namely the numbers:

enter image description here

The problem is, there is a lot of content on that page and I don't know the first step I would take to break it all down.

Does anyone know a way to do this in PHP or jQuery?

Thanks

2012-04-05 23:36
by Sandeep Bansal
Do you need to process it on the server, or just show it to the user? PHP is the choice if it needs to save the data, or make other data dependent on it? Cross-domain in JQUERY is sometimes pretty tricky, but still possible. What is the goal of the data - Marco Johannesen 2012-04-05 23:40
The goal is to be able to match against our lottery numbers to see if we have won, this way it's all automated and we don't have to check through so many lines of numbers every draw - Sandeep Bansal 2012-04-05 23:43


3

what about an existing rss feed http://www.alllotto.co.uk/rss/latest.rss

2012-04-05 23:51
by Ronnie
I was looking everywhere for a plain and simple feed, thanks a lot - Sandeep Bansal 2012-04-05 23:54
I must say it took me a good 5 minutes to find it. I knew something like it had to already exist. I looked all over the www.national-lottery.co.uk site for one but couldn't find i - Ronnie 2012-04-05 23:55


2

I would take a look at the PHP Simple HTML DOM Parser. It simplifies scraping and does what you're asking.

Using this, finding LI elements is as easy as this:

foreach($html->find('li') as $element) {
       echo $element . '<br>';
}
2012-04-05 23:41
by Norse
Ads