简体   繁体   中英

PHP HTML DOM parsing of live PHP content?

So here's something funny.

I'm trying to take the contents of a tweet based on a search, send them to an RTF file and do some other things with them later (art installation; as weird as it sounds). The Twitter stuff works fine — it grabs a random tweet, parses the actual tweet text, and outputs it to a page in <p> tags. Good stuff.

I'm using SC Chen's excellent Simple PHP HTML DOM Parser , which I've used before for similar stuff, to parse the resulting page and isolate the <p> tags (the only set on the page). For some reason, it's not returning anything.

The Twitter crawler file needs to run remotely for it to work with Twitter's 1.1 API. The thing which makes the RTF file needs to run locally, because it gets sent to a printer via an Automator script and some trickery.

remote.php

<p><?php        
[stuff that all works fine]
$tweet = $data[$pick];
$print = $tweet['text'];
print $print;    
?></p>

local.php

<?php
include('simple_html_dom.php');
$url = file_get_html("http://path/to/remote.php");
echo $url;
?>

So, like I said, this is outputting with no content. My local Apache error_log has no errors (aside from when I hilariously tried to include() the remote file, because security is my number three priority).

Any ideas? Does the remote content simply not exist when this request is being made? Is there a way to force the remote content to be available as soon as the local file calls for it, and keep it dynamic and real-time?

我通过将$ print值写入html文件来解决此问题,然后使用本地脚本解析该文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM