Jump to content

How To Grab Content Of Another Site Using Php Culr


bullex

Recommended Posts

Hi Everybody!

I'm new to php programming and have no clue on doing this. I need to create a script to connect to another webshop and get all products from all categories and then save this informations to a database. I have a little script but i dont't know how to continuous.

 

<?php

 

function get_file($url){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);

curl_setopt($ch, CURLOPT_TIMEOUT_MS, 44000);

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');

$html = curl_exec($ch);

curl_close($ch);

return $html;

}

 

function getPage($html){

 

$page = 1;

 

if ( preg_match("/<ol><span class=\"pppt\">([0-9]+) products found<\/span>/", $html, $rez) ) {

 

$page = ceil($rez[1] / 100);

 

} elseif ( preg_match("/<ol><span class=\"pppt\">Viewing all ([0-9]+) products<\/span>/", $html, $rez) ) {

 

$page = ceil($rez[1] / 100);

 

} return $page;

 

}

$url = "http://www.website.com/produs-";

echo get_file($url);

function getColcode($html){

 

if ( preg_match_all('`http://images.website.com/images/products/([0-9]{8})_.*.jpg`Usi', $html, $rez) ) {

 

return $rez[1];

 

} return false;

 

}

 

?>

Link to comment
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.