【发布时间】:2012-09-24 03:06:57
【问题描述】:
我正在做爬虫项目,我需要你的帮助,这是我的第一个项目。任务是从“http://justdial.com”获取数据。例如,我想获取城市名称(班加罗尔)、类别(酒店)、酒店名称、地址和电话号码。
我已经编写了一个代码来从它的“id”中获取标签内容,就像我从这里获取地址一样:
<?php
$url="http://www.justdial.com/Bangalore/hotels";
$original_file = file_get_contents("$url");
$stripped_file = strip_tags($original_file, "<div>");
$newlines="'<div class=\"logoDesc\">(.*?)</div>'si";
$newlines=preg_replace('#<div(?:[^>]*)>.</div>#u','',$newlines);
preg_match_all("$newlines", $stripped_file, $matches);
//DEBUGGING
//$matches[0] now contains the complete A tags; ex: <a href="link">text</a>
//$matches[1] now contains only the HREFs in the A tags; ex: link
header("Content-type: text/plain"); //Set the content type to plain text so the print below is easy to read!
$path= ($matches);
print_r($path); //View the array to see if it worked
?>
现在的问题是,我想将标签与内容分开并将其存储在数据库中。从数据库到excel表。请帮帮我。
【问题讨论】:
-
你的意思是
strip_tags()? -
路径包含什么?请给我们看一个转储。您是否尝试过任何数据库代码?是否需要从数据库-> excel,或者可以同时生成excel表?它必须是 xls,还是 csv 就足够了?
标签: php parsing html-parsing web-crawler