크롤러 프로젝트를 진행하고 있는데 도움이 필요합니다. 이것이 내 첫 번째 프로젝트입니다. 작업은 'http://justdial.com'에서 데이터를 가져 오는 것입니다. 예를 들어 도시 이름 (뱅 골어), categoury (호텔), 호텔 이름, 주소 및 전화 번호를 가져오고 싶습니다.PHP 크롤러 (단일 웹 사이트 크롤링)
나는이에서 주소를 가져 한 것처럼, 그 '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
?>
지금 문제가, 내가 내용에서 태그를 분리해서 원하는됩니다 그것을 데이터베이스에 저장하십시오. 그리고 데이터베이스에서 엑셀 시트. 도와주세요.
'strip_tags()'를 의미합니까? –
경로에는 어떤 것이 포함되어 있습니까? 우리에게 덤프를 보여주십시오. 데이터베이스 코드를 아직 사용해 보지 않으셨습니까? 데이터베이스 -> 엑셀로 이동해야하거나 엑셀 시트를 동시에 생성 할 수 있습니까? 그것은 xls이어야합니까, 아니면 CSV로 충분합니까? – LeonardChallis
[MySQL] (http://php.net/mysqli)와 [fputcsv] (http://php.net/fputcsv)를 의미합니까? – Touki