【问题标题】:Web crawler script not working for calender events网络爬虫脚本不适用于日历事件
【发布时间】:2012-12-14 07:14:16
【问题描述】:

我写了一个网络爬虫脚本 代码是::

<?php
include_once('simple_html_dom.php');
$target_url = "http://jvlaunchcalendar.com/calendar/";
$html = new simple_html_dom();
$html->load_file($target_url);
$ret = $html->find('div[class=fc-event-inner'); 
//to print the caleder events similar code //works for other sites like flipcat.com
foreach($ret as $post)
{
    echo $post.'<br />';
}
echo $html;// to print the calender of jvlaunchcalendar.com site
?>

此脚本适用于其他网站。 但是我想要http://jvlaunchcalendar.com/calendar/ 页面的所有日历事件,但是这个脚本不显示任何事件给空日历。 请帮我获取日历的事件。

问候。

【问题讨论】:

  • 似乎不包含任何具有此类的 div。
  • 加载内容后输出整个$html,看看你会得到什么。
  • div 在那里请再次检查我已经从日历中粘贴了这个类。但是当我想获取 $html 的完整页面时,它不会显示任何日历事件为空日历。
  • 所以我在说什么。从 ajax 请求加载日历。所以当你“加载”页面时它是空的。
  • 您是如何知道日历事件来自 ajax 的。请告诉我任何解决方案。

标签: php web-crawler


【解决方案1】:

当您尝试$html-&gt;load_file($target_url); 时,您会看到没有事件的空白页面,因为事件是使用 ajax 加载的。

获取事件的简单解决方案:跟踪 ajax url 调用并加载它,而不是页面。 (我检查了,它返回json 数据,一切正常)。

但这并不好。其他方式 - 在 WordPress 中使用本机日历功能进行操作。

【讨论】:

  • 我只使用 php。我现在试试你的解决方案
  • 你能告诉我更多吗?
  • 还有一点是:1.在浏览器中打开开发工具; 2.跟踪ajax调用; 3. 找出带有数据的url; 4. 在你的 php 脚本中加载这个 url; 5. 利润!
  • 那又怎样?你有 json 事件数据。任务完成。问题解决了。
猜你喜欢
  • 1970-01-01
  • 2021-08-20
  • 2017-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多