使用 php 进行数据抓取

Data Scraping with php

我想使用 php 抓取数据。但我不明白我哪里错了。 我想收到“15,50 TL”文本。谢谢

<?php

function find($start, $close, $where)
{
    @preg_match_all('/' . preg_quote($start, '/') .
    '(.*?)'. preg_quote($close, '/').'/i', $where, $m);
    return @$m[1];
}

$url = "https://www.bynogame.com/Knight-Online/Gold-Bar";

$fulldata = file_get_contents($url);

$akara = find('<td align="center" nowrap="nowrap">','<form name="urunayrinti38154"></form></td>',$fulldata);

print_r($akara);

?>

问题是 $start$close 字符串在页面中找不到。

有一个<td align="center" nowrap="nowrap">,在td标签名和align属性之间有2个空格,还有一个<form name="urunayrinti38154"> 没有其余部分的字符串。

恕我直言,更好的方法是使用 DOM 解析库,例如 Symfony 的 DomCrawler component, or PHP's own XML Manipulation functions, such as DOMDocument::loadHTMLFile().