【发布时间】:2011-05-24 21:02:04
【问题描述】:
我有一个问题 - 一个无法解析的解析器。这没用!它不回馈任何东西!好吧,我想取回一些东西 - 并将结果存储在 mysql 数据库中。
<?PHP
// Original PHP code by Chirp Internet: http://www.chirp.com.au
// Please acknowledge use of this code by including this header.
$url = "http://www.edi.admin.ch/esv/00475/00698/index.html?lang=de";
//$input = @file_get_contents($url) or die("Could not access file: $url");
$input = file_get_contents($url) or die("Could not access file: $url");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
// $match[2] = all the data i want to collect...
// $match[3] = text that i need to collect - see a detail-page
}
}
?>
这有点超出我的想象:它没有返回任何结果。我必须将file_get_contents() 与查询字符串一起使用吗?
【问题讨论】:
-
你确定你使用 file_get_contents 从 url 中得到了一些东西吗?
-
请说出它的作用。不工作不是问题。
-
用正则表达式解析HTML请参考this答案。
-
你真的知道“查询字符串”是什么意思吗?还有为什么你之前关于同一主题的问题会出现回归(正则表达式提取而不是实际的 dom 解析)?
-
您假设
file_get_contents()可以访问远程文件,但事实上,它并不总是这样做。这取决于特定设置,出于安全原因,该设置大部分时间都处于关闭状态。
标签: php mysql parsing file curl