gpt4 book ai didi

php - SimpleXML->xpath 问题

转载 作者:行者123 更新时间:2023-12-03 16:13:00 26 4
gpt4 key购买 nike

我正在尝试访问每个表行:

http://www.alliedelec.com/search/searchresults.aspx?N=0&Ntt=PIC16F648&Ntk=Primary&i=0&sw=n



使用 SimpleXML->xpath。我已确定表的 xpath 为:
'//*[@id="tblParts"]'

现在我使用我的 cURL 字符串 $string 并执行以下操作:
$tidy->parseString($string);
$output = (string) $tidy;
$xml = new SimpleXMLElement($output);
$result = $xml->xpath('//*[@id="tblParts"]');
while(list( , $node) = each($result))
{
echo 'NODE:' . $node . "\n";
}

我得到的是这样的错误,成百上千:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 60: parser error : Opening and ending tag mismatch: meta line 22 and head in C:\xampp\htdocs\elexess\api\driver\driver_alliedelectronics.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </head> in C:\xampp\htdocs\elexess\api\driver\driver_alliedelectronics.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in C:\xampp\htdocs\elexess\api\driver\driver_alliedelectronics.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 108: parser error : Opening and ending tag mismatch: img line 106 and td in C:\xampp\htdocs\elexess\api\driver\driver_alliedelectronics.php on line 119

最后还有这个:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\app\com\get\get_alliedelectronics.php:119 Stack trace: #0 C:\xampp\htdocs\app\com\get\get_alliedelectronics.php(119): SimpleXMLElement->__construct('<!DOCTYPE html ...') #1 C:\xampp\htdocs\app\com\get\get_alliedelectronics.php(95): get_Alliedelectronics->extractData('<!DOCTYPE html ...') #2 C:\xampp\htdocs\app\com\get\get_alliedelectronics.php(138): get_Alliedelectronics->query('PIC16F648') #3 {main} thrown in C:\xampp\htdocs\app\com\get\get_alliedelectronics.php on line 119

最佳答案

看起来您正在获取并尝试解析的页面的 HTML 格式不正确(标签不匹配等)

您可以尝试使用 simplexml_import_dom 修复错误正如我在 this SO post 中解释的那样.

关于php - SimpleXML->xpath 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5927879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com