我正在尝试用 xpath 抓取一些数据,然后插入到 SQL 中。
Echo 工作正常,但插入 sql 时,它只得到第一行。
例子:
<?php
$res=mysql_query("SELECT table.title, table.link FROM table WHERE table.link LIKE 'http://www.%' AND streams.title = ''");
while($row=mysql_fetch_array($res))
{
$html = new DOMDocument();
@$html->loadHtmlFile($row["link"]);
$xpath = new DOMXPath($html);
foreach ($xpath->query("//table[@style='margin-left: 5px;']//td[@width='150']//a") as $files)
{
$html = new DOMDocument();
@$html->loadHtmlFile($files->getAttribute('href'));
$xpath = new DOMXPath($html);
$hl = $xpath->query("//div[@style='width:742px']/a[preceding-sibling::div[@id='help1']]/@href")->item(0)->nodeValue;
$link=serialize(array('link' => $hl));
$link=sqlesc($link);
echo $link; // all lines gets printed, thats okay?
mysql_query("UPDATE streams SET streams.hl=$link") or die(mysql_error()); // Only first line gets inserted, why?
}
}
?>