【问题标题】:How to scrape data from justdial.com?如何从 justdial.com 抓取数据?
【发布时间】:2017-12-08 13:02:54
【问题描述】:

我想从上述网站获取所有电话号码和医生姓名。我目前面临一些关于抓取数据的问题。我已经下载了用于抓取的 html 页面,但显示错误错误是

警告: file_get_contents(file:///C:/Program%20Files%20(x86)/xampp/htdocs/scrape_demo/Top%20Ayurvedic%20Doctors%20in%20kolkata.html): 无法打开流:C:\Program Files 中没有这样的文件或目录 (x86)\xampp\htdocs\scrape_demo\simple_html_dom.php 在第 75 行

致命错误:在非对象上调用成员函数 find() C:\Program Files (x86)\xampp\htdocs\scrape_demo\scrape_justdial.php 第 4 行

这是我的代码 -

<?php
    include_once('simple_html_dom.php');
    $html = file_get_html('file:///C:/Program%20Files%20(x86)/xampp/htdocs/scrape_demo/Top%20Ayurvedic%20Doctors%20in%20kolkata.html');
    foreach($html->find('div.col-sm-5 col-xs-8 store-details sp-detail paddingR0') as $element){
    echo $element->innertext . '<br/>';
}
?>

我正在等待解决方案

【问题讨论】:

  • 我首先要确保您将正确的文件位置传递给您的班级。也不要在文件名中使用空格并使用__DIR__$file = __DIR__ . '/Top_Ayurvedic_Doctors_in_kolkata.html';
  • (file_get_content)[php.net/file_get_content] 不知道文件协议。只需使用正确的路径,如C:/Program%20Files%20(x86)/xampp/htdocs/scrap_demo/Top%20Ayurvedic%20Doctors%20in%20kolkata.html
  • 谢谢。现在问题解决了
  • @NicoHaase 发表您的评论作为答案。

标签: php web-scraping


【解决方案1】:

file_get_content 不知道文件协议。只需使用正确的路径,如C:/Program%20Files%20(x86)/xampp/htdocs/scrape_demo/Top%20Ayu‌​rvedic%20Doctors%20i‌​n%20kolkata.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2017-05-14
    相关资源
    最近更新 更多