且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何找到这个div? (PHP简单的HTML DOM解析器)

更新时间:2022-04-09 23:15:42

我对您的代码进行了更改对于这个类:

I made a change to your code where I am searching for the class:

<?php
    include('simple_html_dom.php');
    $html = file_get_html('http://www.google.com/search?q=BA236',false);
    $e = $html->find("div[class=g]");
echo $e[0]->innertext;
?>

结果:

result:

British Airways Flight 236

Scheduled   departs in 13 hours 13 mins

Departure   DME 5:40 AM     —

Moscow  Dec 15      

Arrival LHR 6:55 AM     Terminal 5

London  Dec 15      

Scheduled   departs in 1 day 13 hours

Departure   DME 5:40 AM     —

Moscow  Dec 16      

Arrival LHR 6:55 AM     Terminal 5

London  Dec 16      

我用g类寻找div元素,然后打印出第一个元素'0'的计数

I looked for the div elements with class g then I printed the count of the first element '0'

$e = $html-> find ("div [class = g]");
echo $e [0]->innertext;

您的代码:

Your code:

<?php
    include('simple_html_dom.php');
    $html = file_get_html('http://www.google.com/search?q=BA236',false);
    $title=$html->find('div[class=g]')[0]->innertext;
    echo $title;
?>

不是('div [class = g],0') code>

('div [class = g]')[0]