在相同的HTML pageThere're兩個不同的格式解析HTML頁面相同的兩種不同格式包含:具有上相同的元件
第一是:
<div class="gs"><h3 class="gsr"><a href="http://www.example1.com/">title1</a>
第二個是:
<div class="gs"><h3 class="gsr"><span class="gsc"></span><a href="http://www.example2.com/">title2</a>
如何獲得一個代碼中的鏈接和標題,可以使用simple_html_dom處理這兩種不同的格式? 我試過這個代碼,但它不工作:
foreach($html->find('h3[class=gsr]') as $docLink){
$link = $docLink->first_child();
echo $link->plaintext;
echo $link->href;
}
但你爲什麼問這裏幾乎相同的問題? http://stackoverflow.com/questions/11533705/parsing-title-and-link-from-html-page – Tamil 2012-07-18 11:27:12
@泰米爾是的,我有新的問題。它不同於那個頁面。在上一個問題中,我只是確定了一個html頁面的格式。然後我意識到在相同的元素上有兩種格式。所以我在這裏提出了新的問題。 – 2012-07-18 11:38:24