任何人可以幫助/建議,有沒有什麼辦法來解析HTML標籤的最佳方式出現在側<body>...</body>
標籤解析HTML標籤的Java腳本
0
A
回答
2
我想你想用PHP解析HTML文檔。我建議你閱讀有關
下面是PHP Pro
<?php
$html = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" dir="ltr">
<head>
<title>PHPRO.ORG</title>
</head>
<body>
<h2>Forecast for Saturday</h2>
<!-- Issued at 0828 UTC Friday 23 May 2008 -->
<table border="0" summary="Capital Cities Precis Forecast">
<tbody>
<tr>
<td><a href="/products/IDN10064.shtml" title="Link to Sydney forecast">Sydney</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">19°</td>
<td>Fine. Mostly sunny.</td>
</tr>
<tr>
<td><a href="/products/IDV10450.shtml" title="Link to Melbourne forecast">Melbourne</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">16°</td>
<td>Fog then fine.</td>
</tr>
<tr>
<td><a href="/products/IDQ10095.shtml" title="Link to Brisbane forecast">Brisbane</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">24°</td>
<td>Mostly fine</td>
</tr>
<tr>
<td><a href="/products/IDW12300.shtml" title="Link to Perth forecast">Perth</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">21°</td>
<td>Few showers, increasing later.</td>
</tr>
<tr>
<td><a href="/products/IDS10034.shtml" title="Link to Adelaide forecast">Adelaide</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">20°</td>
<td>Fine. Mostly sunny.</td>
</tr>
<tr>
<td><a href="/products/IDT65061.shtml" title="Link to Hobart forecast">Hobart</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">13°</td>
<td>Mainly fine.</td>
</tr>
<tr>
<td><a href="/products/IDN10035.shtml" title="Link to Canberra forecast">Canberra</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">15°</td>
<td>Fine, mostly sunny.</td>
</tr>
<tr>
<td><a href="/products/IDD10150.shtml" title="Link to Darwin forecast">Darwin</a></td>
<td title="Maximum temperature in degrees Celsius" class="max alignright">32°</td>
<td>Fine and sunny.</td>
</tr>
</tbody>
</table>
</body>
</html>
';
/*** a new dom object ***/
$dom = new domDocument;
/*** load the html into the object ***/
$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
foreach ($rows as $row)
{
/*** get each column by tag name ***/
$cols = $row->getElementsByTagName('td');
/*** echo the values ***/
echo $cols->item(0)->nodeValue.'<br />';
echo $cols->item(1)->nodeValue.'<br />';
echo $cols->item(2)->nodeValue;
echo '<hr />';
}
?>
+0
我以爲他在尋找一個JavaScript解決方案,而不是PHP。 – JasonMichael 2010-05-12 13:02:20
+1
我也是第一次,但注意到了標籤 – John 2010-05-12 14:20:37
0
提供您可以從另一個頁面通過ajax加載整個HTML文檔,並使用jQuery選擇解析它的例子 - 如果它是XHTML。不知道這是否能正常工作。
2
你的意思是類似於John Resig's html parser?
相關問題
- 1. 解析HTML標籤
- 2. PHP解析器:解析HTML標籤後的HTML文本
- 3. HTML解析中的標籤
- 4. 用html標籤解析文本
- 5. 解析Adobe InDesign的HTML文本 - 其他標籤內的標籤
- 6. 包含腳本標記和LineNumberReader的Java HTML解析器
- 7. 用java腳本更改html「for」標籤
- 8. 解析HTML標籤JSON角
- 9. NSXMLParser不解析html標籤
- 10. Jsoup解析HTML標籤頁
- 11. 解析HTML檢索標籤
- 12. PHP解析HTML標籤
- 13. HTML標籤無法解析圖標「&#xf2bc;」
- 14. Angular2:HTML標籤的解析數據
- 15. 解析沒有HTML標籤的數據
- 16. 解析出Nokogiri中的html doctype標籤
- 17. Jsoup HTML解析與特定的標籤
- 18. 解析來自HTML中的單詞和標籤在Java中
- 19. 腳本的HTML解析順序
- 20. java xml標籤之間的解析
- 21. 解析標籤
- 22. 在rails上解析html標記和腳本標記
- 23. C#HTML字體標籤解析
- 24. HTML解析器忽略img標籤(Golang)
- 25. SAX解析器忽略CDATA - html標籤
- 26. 在xml sqlserver中解析html標籤
- 27. 解析HTML和用C#計數標籤
- 28. Android:在JSON中解析HTML標籤
- 29. 使用BeautifulSoup解析HTML標籤
- 30. HTML解析/檢查某些標籤
我想我們需要更多的細節來說明你想要達到的目標。 – Matt 2010-05-12 12:03:50