यह काम करना चाहिए, लेकिन यह गंदा है और संभव साइट पर आप स्क्रैप कर रहे हैं यह मार्कअप जो scraping को प्रभावित करेगा है बदलने के लिए होता है अगर यह टूट जाएगा:
$sites[0] = 'http://www.traileraddict.com/';
// use this if you want to retrieve more than one page:
// $sites[1] = 'http://www.traileraddict.com/trailers/2';
foreach ($sites as $site)
{
$ch = curl_init($site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
// ok, you have the whole page in the $html variable
// now you need to find the common div that contains all the review info
// and that appears to be <div class="info"> (I think you could use abstract aswell)
$title_start = '<div class="info">';
$parts = explode($title_start,$html);
// now you have an array of the info divs on the page
foreach($parts as $part){
// so now you just need to get your title and link from each part
$link = explode('<a href="/trailer/', $part);
// this means you now have part of the trailer url, you just need to cut off the end which you don't need:
$link = explode('">', $link[1]);
// this should give something of the form:
// overnight-2012/trailer
// so just make an absolute url out of it:
$url = 'http://www.traileraddict.com/trailer/'.$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('$host', '$user', '$password') or die('error');
mysql_select_db('$database', $db_conn) or die(mysql_error());
$sql = "INSERT INTO trailers(url, title) VALUES ('".$url."', '".$title."')"
mysql_query($sql) or die(mysql_error());
}
यह होना चाहिए, अब आपके पास लिंक और शीर्षक के लिए एक चर है जिसे आप अपने डेटाबेस में सम्मिलित कर सकते हैं।
अस्वीकरण
मैंने कार्यस्थल पर अपने सिर के ऊपर से लिखा है तो मैं माफी माँगता हूँ अगर यह बल्ला बंद सीधे काम नहीं करता है, लेकिन मुझे पता है कि अगर ऐसा नहीं होता है और मुझे कोशिश करते हैं और करेंगे आगे मदद करें।
ALSO, मुझे पता है कि यह बेहतर हो सकता है और कम चरणों का उपयोग कर सकता है लेकिन इसमें मेरे हिस्से पर और सोच शामिल होगी और ओपी यह कर सकता है अगर वे एक बार कोड लिखने के बाद चाहते हैं, क्योंकि मैं मानता हूं यह बहुत महत्वपूर्ण होगा कि वे समझें कि मैंने क्या किया है और इसे स्वयं संपादित करने में सक्षम हैं।
इसके अलावा, मैं रात को साइट को स्क्रैप करने की सलाह दूंगा ताकि अतिरिक्त ट्रैफ़िक के साथ इसे बोझ न किया जा सके और मैं सुझाव देता हूं कि उस साइट की अनुमति मांगने के साथ ही अगर वे आपको पकड़ लेते हैं तो वे आपके लिए अंत कर पाएंगे स्क्रैप :(
अपने अंतिम बिंदु का उत्तर देने के - किसी नियत समयावधि आप एक क्रॉन जॉब का प्रयोग करेंगे पर इस चलाने के लिए
मैं कुछ php स्क्रिप्ट (कर्ल और file_get_contents) जो मैं net.but में पाया की कोशिश की है। उन स्क्रिप्ट केवल पूरे वेबपृष्ठ को लाते हैं और विशिष्ट डेटा नहीं। मुझे यह भी नहीं पता कि उन डेटा को मेरे mysql डेटाबेस में कैसे सहेजना है – Eka
google phpquery या htmlsql या simplehtmldom पर खोजें – Sarfraz