Jump to content

Recommended Posts

Can someone please help me with the regex.I am trying to scrape the data.Below is the pattern of data in the source code i would like to scrape.I would like to get

 

Name,Address,City,State,Country,Pincode,Phone number and Category

 

Pattern of Data :-

 

<div align="center"><center><table border="0"
        cellpadding="3" cellspacing="0" width="350"> 
            <tr> 
                <td valign="top" width="350" bgcolor="#FFFFFF"<div align="center"><table
                border="1" cellpadding="12" cellspacing="0"
                width="100%" bgcolor="#FFFFE6"
                bordercolor="#000000" bordercolordark="#808080"
                bordercolorlight="#C0C0C0"> 
                    <tr> 
                        <td colspan="2" width="350"><font
                        size="2"> 

<b>  Name   </b><br>Address <br>City, State 
<br>Country, Pincode   <BR><BR><font size="2"><img src="../images/ph.gif"
                        align="left" hspace="4" alt = "AL0674"> - Phone #             x-xxx-xxx-xxxx         </font>  <BR>   <font size ="1"> 

<BR>Category: Something
<BR>Something
<BR>Something

</font></td> 
                    </tr> 
                </table> 
                </td> 
            </tr> 
        </table> 

        </center></div>

 

 

I tried it myself but i am getting warning with it.

 

Code -

 

<?php

$data = file_get_contents('http://xxx.com');
$regex = '/~<tr>\s+<td\s+colspan="2"\s+width="350"><font\s+size="2">\s+<b>(.*?)</b><br>(.*?<br>(.*?), (.*?)\s+<br>(.*?), (.*?)   <BR><BR><font\s+size="2"><img\s+src="../images/ph.gif"\s+align="left"\s+hspace="4"\s+alt\s+=\s+"AL0674">\s+-\s+Phone #   (.*?) </font>~/';
preg_match($regex,$data,$match);
var_dump($match); 
echo $match[1];
?>

 

Warning message i am getting :-

Warning: preg_match() [function.preg-match]: Unknown modifier 'b' in C:\Users\Boone\AppData\Roaming\NuSphere\PhpED\projects\scrapingtest.php on line 5
NULL 

 

 

Link to comment
https://forums.phpfreaks.com/topic/229187-regex-help-for-scraping-data/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.