June 8, 2010

How to rip specific data from an HTML file?

Question by SnirD

so I have multiple HTML files which I need to get some praticular data from, I mean theres a bunch of non relative information in this HTML files, but I need just lets say things that are between the <div class="myInfo"> and </div>, after getting this information I want to handle it in my own PHP page, so for example I can insert this data into some variables. Is it even possible using PHP only?
(Forgive me for my English mistakes)

Answer by RobertPitt

I would use SimpleDom

http://simplehtmldom.sourceforge.net/

// Find all article blocks
foreach(file_get_html('http://smysite.com')->find('div.myInfo') as $Info) {
    print_r($Info);
}

Alternative.
http://php.net/manual/en/book.simplexml.php

Answer by Starx

I think you need to use CURL for that

Here is a link
http://www.php.net/manual/en/book.curl.php

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!