开发者

Simple HTML dom parser for multiple URLs

开发者 https://www.devze.com 2023-02-14 07:51 出处:网络
I\'m parsing fine from one url, but how do i add a second source url in the same file. e.g. $html = file_get_html(\'http://google.com\');

I'm parsing fine from one url, but how do i add a second source url in the same file.

e.g.

$html = file_get_html('http://google.com');

for one 开发者_C百科url, but how to add second source and make it work with "echo" function?

Thanks


I don't think most parsers will let you add invalid duplicated tags like <head> and <body>. You could try by first parsing both URLs and extracting their bodies:

$page1 = file_get_html('url1');
$body1 = $page1->find('body');

$page2 = file_get_html('url2');
$body2 = $page2->find('body');

Then get them together and parse back:

$body1 = $body1->plaintext;
$body2 = $body2->plaintext;
$bodies = str_get_html($body1.$body2);
0

精彩评论

暂无评论...
验证码 换一张
取 消