I want to store:
- Product Name
- Categoty
- Subcategory
- Price
- Product Company.
In my table named products_data with filds name as PID, product_name, category, subcategory, product_price and product_company.
I am using curl_init()
function in php to first scrap website URL, next I want to store products data in my database table. Here is what I have done so far for this:
$sites[0] = 'http://www.babyoye.com/';
foreach ($sites as $site)
{
$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
$title_start = '<div class="info">';
$parts = explode($title_start,$html);
foreach($parts as $part){
$link = explode('<a href="/d/', $part);
$link = explode('">', $link[1]);
$url = 'http://www.babyoye.com/d/'.$link[0];
// now for the title we need to follow a similar process:
$title = explode('<h2>', $part);
$title = explode('</h2>', $title[1]);
$title = strip_tags($title[0]);
// INSERT DB CODE HERE e.g.
$db_conn = mysql_connect('localhost', 'root', '') or die('error');
mysql_select_db('babyoye', $db_conn) or die(mysql_error());
$sql = "INSERT INTO products_data(PID, product_name) VALUES ('".$url."', '".$title."')"
mysql_query($sql) or die(mysql_error());
}
}
I am little confused with database part that how to insert data in table. Any help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…