file_get_contents,来自站点的数据

发布于 2024-09-30 13:16:45 字数 129 浏览 7 评论 0原文

您好,我想要来自其他网站表单 http://www.dailyfx.com/calendar & 的一些数据。我只想要该网站的日历。没有别的。 我也检索数据但破坏页面数据。

请帮助我。

Hello i want some data from other site form http://www.dailyfx.com/calendar & i want only calander form that site. nothing else.
also i retrive the data but hole the page data.

Kindly help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2024-10-07 13:16:45

好吧,我只是以 CSV 格式获取它,因为它们有那些方便的下载链接......比抓取所有 HTML 容易得多:

$dom = new DomDocument('1.0');
$dom->validateOnParse = false;
$dom->loadHtmlFile('http://www.dailyfx.com/calendar');
$xpath = new DomXpath($dom);
$csvFileLink = $xpath->query("//div[@id='e-cal-control-bot-export']/a[contains(@href, '.csv')]/@href");

if($url = $csvFileLink->item(0)->textContent)
{
  if(0 === strpos($url, '/')){
    $url = 'http://www.dailyfx.com' . $url;
  } else {
    $url = 'http://www.dailyfx.com/calendar/'.$url;
  }

  $csvData = file_get_contents($url);
}

print $csvData;

当然......你可能想确保你在法律上是明确的,具体取决于你打算如何使用数据....

Well i woudl jsut grab it in CSV format since they have those handy download links... alot easier than scraping all the HTML:

$dom = new DomDocument('1.0');
$dom->validateOnParse = false;
$dom->loadHtmlFile('http://www.dailyfx.com/calendar');
$xpath = new DomXpath($dom);
$csvFileLink = $xpath->query("//div[@id='e-cal-control-bot-export']/a[contains(@href, '.csv')]/@href");

if($url = $csvFileLink->item(0)->textContent)
{
  if(0 === strpos($url, '/')){
    $url = 'http://www.dailyfx.com' . $url;
  } else {
    $url = 'http://www.dailyfx.com/calendar/'.$url;
  }

  $csvData = file_get_contents($url);
}

print $csvData;

Of course.. you might want to make sure youre in the clear legally depending on how you intend to use the data....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文