【发布时间】:2019-12-15 13:18:13
【问题描述】:
所以我和哥哥决定使用 CURL 和 Dom 解析网站中的 xml 内容。
当我尝试回显 dom 部分的各个方面时,我不断得到一个空白的返回值。
这里有一些细节:
- 我们正在 CURLing 和使用 Dom 的示例网站 url 是这样的:https://event.on24.com/eventRegistration/EventServlet?eventid=2062141&sessionid=1&key=FD3181776AA1D3051A0CE6249F1A391A&filter=eventsessionmediapresentationlogplayerxmlformateventrootmediabaseurldialininfomobileenvondemandexcludequestionexcludemessagesexcludeslides
- 请注意,URL 不是 XML 文件的直接路径。但是在 该页面具有 XML 内容。尝试点击链接,你会看到 我的意思。
- 我想打印标签之间的内容。
- 我使用 CURL 和 Dom 脚本的方式要么不正确,要么有其他问题。
我在代码的不同区域尝试了各种回显,但都返回了一个空白值。当我尝试echo $parsedcontent 时,它会出现一个空白。
当我尝试在“Foreach...'span' as...”之后回显“Hello World”时,它不会打印任何内容。
$urlcontent = $event['url'];
$chcontent = curl_init();
$timeoutcontent = 5;
curl_setopt($chcontent, CURLOPT_URL, $urlcontent);
curl_setopt($chcontent, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chcontent, CURLOPT_CONNECTTIMEOUT, $timeoutcontent);
curl_setopt($chcontent, CURLOPT_SSL_VERIFYPEER, false);
$htmlcontent = curl_exec($chcontent);
$infocontent = curl_getinfo($chcontent);
curl_close($chcontent);
@$domcontent->loadXML($htmlcontent);
foreach($domcontent->getElementsByTagName('span') as $spanon24content) {
# Get url and title from <a> tags
$innerHTMLspan = '';
$childrenspan = $spanon24content->childNodes;
foreach ($childrenspan as $childspan) {
$innerHTMLspan .= $divspanon24content->ownerDocument->saveXML($childspan);
}
}
$parsedcontent = $innerHTMLspan;
echo $parsedcontent;
【问题讨论】:
-
我认为这个问题的答案可能会为您指明正确的方向:stackoverflow.com/questions/6674322/…
-
I keep on getting a blank return value when I try to echo various aspect of the dom parts.- 调试时,使用 var_dump(),而不是 echo(),以避免此问题。还要确保 php.ini 有error_reporting=E_ALL和display_error=on(或者,确保错误日志有效,并在运行代码后阅读错误日志) -
Try to click on the link, you'll see what I mean.链接是什么意思?您的测试 XML 页面有 80 个不同的链接!您指的是 80 个链接中的哪一个? -
I am wanting to print the content between the tags.你说的是哪个标签,有3679个标签,你要all之间的内容吗?
标签: php xml curl dom xml-parsing