-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$html = '<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>test</title> | ||
</head> | ||
<body> | ||
<p class="test_class test_class1">p1</p> | ||
<p class="test_class test_class2">p2</p> | ||
<p class="test_class test_class3">p3</p> | ||
<div id="test1"><span style="display: none">测试1<br/></span><input date=\'"sdfsf"\' name="test" value="123"/>123123</div> | ||
</body> | ||
</html>'; | ||
|
||
$html_dom = new \HtmlParser\ParserDom($html); | ||
$p_array = $html_dom->find('p.test_class'); | ||
$p1 = $html_dom->find('p.test_class1',0); | ||
$div = $html_dom->find('div#test1',0); | ||
foreach ($p_array as $p){ | ||
echo $p->getPlainText() . "\n"; | ||
} | ||
echo $div->getPlainText() . "\n"; | ||
echo $p1->getPlainText() . "\n"; | ||
echo $p1->getAttr('class') . "\n"; | ||
|
||
echo "show html:\n"; | ||
echo $div->innerHtml() . "\n"; | ||
echo $div->outerHtml() . "\n\n"; | ||
|
||
|
||
$url = 'http://www.sina.com.cn/'; | ||
$sHtml = file_get_contents($url); | ||
|
||
$oDom = new \HtmlParser\ParserDom($sHtml); | ||
$oFound = $oDom->find('ul.uni-blk-list02', 0); | ||
for($i = 0; $i < 10000; $i ++) { | ||
test($sHtml); | ||
if($i % 100 == 0) { | ||
echo $i . ' '; | ||
echo round(memory_get_usage() / 1024 / 1024, 3) . 'M, '; | ||
echo round(memory_get_peak_usage() / 1024 / 1024, 3) . 'M' . "\n"; | ||
} | ||
} | ||
|
||
echo "inner:\n\n" . $oFound->innerHtml() . "\n\n"; | ||
echo "outer:\n\n" .$oFound->outerHtml() . "\n"; | ||
echo round(memory_get_usage() / 1024 / 1024, 3) . 'M, '; | ||
echo round(memory_get_peak_usage() / 1024 / 1024, 3) . 'M' . "\n"; | ||
|
||
function test($sHtml) { | ||
$oDom = new \HtmlParser\ParserDom($sHtml); | ||
$oDom->find('ul.uni-blk-list02', 0); | ||
$oDom->find('a'); | ||
$oDom->find('ul'); | ||
$oDom->find('p'); | ||
} |