Jump to content

Screen Scraping


Lytheum

Recommended Posts

I need to pull some info off a certain website that is setup like this:

 

<b>Blah1:</b> 11<br/>
<b>Blah2:</b> 22<br/>
<b>Blah3:</b> 33<br/>
<b>Blah4:</b> 44<br/>
<b>Blah5:</b> 55<br/>

 

So I should be able to try:

 

echo "$blah1"; //value of 11
echo "blah5"; //value of 55

 

My code which doesn't work at all, hopefully somebody can improve on it:

 

// Get page
$url = "http://url.url.url";
$data = implode("", file($url)); 

// Get content items
preg_match_all ("/<\/b>([^`]*?)<br\/>/", $data, $matches);

// Loop through each content item
foreach ($matches[0] as $match) {
// First, get title
preg_match ("/<b>Blah1:<\/b>([^`]*?)<br\/>/", $match, $temp);
$title = $temp['1'];
$title = strip_tags($title);
$title = trim($title);
}
echo "$blah1";

 

Thanks for any future help, if you still don't understand lemme know.

Link to comment
https://forums.phpfreaks.com/topic/80743-screen-scraping/
Share on other sites

Try:

 

<?php
$str="<b>Blah1:</b> 11<br/>
<b>Blah2:</b> 22<br/>
<b>Blah3:</b> 33<br/>
<b>Blah4:</b> 44<br/>
<b>Blah5:</b> 55<br/>";
preg_match_all('|Blah([0-9]).*?([0-9]+)|',$str,$matches);
$blah = array();
foreach($matches[1] as $k => $v){
$blah[$v] = $matches[2][$k];
}
echo $blah[1]; //11
echo $blah[5]; //55
?>

Link to comment
https://forums.phpfreaks.com/topic/80743-screen-scraping/#findComment-409589
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.