![](/img/trans.png)
[英]How to insert line of php code in html file, using SimpleHtmlDOM
[英]how to extract raw html code using simplehtmldom
我正在嘗試使用 simplehtmldom 從網頁中提取原始 html。 我想知道是否可以使用該庫。
例如,假設我有一個試圖從中提取數據的網頁。
<div class="class1">
<div class="class2">
<div class="class3">
<p>p1</p>
<h1>header here!</h1>
<p>p2</p>
<img src="someimage"></img>
</div>
</div>
</div>
我的目標是提取 div class3 中的所有內容,包括原始 html 代碼,因此當我獲取數據時,我可以將其輸入到允許輸入源代碼的文本框中,因此它的格式與網頁中的格式相同。
我查看了 simplehtmldom 手冊並進行了一些搜索,但尚未找到解決方案。
謝謝你。
使用您的示例 html 字符串
$html = str_get_html('<div class="class1">
<div class="class2">
<div class="class3">
<p>p1</p>
<h1>header here!</h1>
<p>p2</p>
<img src="someimage"></img>
</div>
</div>
</div>');
// Find all divs with class3
foreach($html->find('div[class=class3]') as $element) {
echo $element->outertext;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.