<?php
$site_page_url = "http://shop.bytravel.cn/";
$site_page_content = file_get_contents($site_page_url);
echo $site_page_content."\n";
preg_match_all("/\"?\/produce\/index.*?\.html/", $site_page_content, $match);
print_r($match);
if (!empty($match[0]) && is_array($match[0])){
$prefix_url = 'http://shop.bytravel.cn/';
$all = [];
$len = count($match[0]);
echo "总共有 {$len} 条记录";
foreach ($match[0] as $i => $url){
$item = getFoodContent($i + 1, $prefix_url. trim($url, "\""));
if ($item){
$all[] = $item;
}
}
$text = "";
foreach ($all as $item){
$str_list = explode(",", $item, 2);
if (count($str_list) == 2){
$text .= $str_list[0] ."\t". $str_list[1]. "\n";
}
}
file_put_contents("food.txt", $text);
}
function getFoodContent($i, $url){
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=> 4,
)
);
$food_page_content = file_get_contents($url, null, stream_context_create($opts));
preg_match("/\"description\" content=\"(.*)?\"/", $food_page_content, $child_match);
echo "完成第 $i 条记录: $url\n";
return empty($child_match[1]) ? null: $child_match[1];
}