Retrieve data contained a certain span class

前端 未结 3 1365
故里飘歌
故里飘歌 2021-01-25 14:52

using file_get_contents, I open an Internet URL and get the contents of this webpage.

Inside the HTML there are many identical span class tags:

<         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 15:25

    If I understood correctly, this has to be PHP as it is on the server, not in the browser. So I'd do something like

    $html=file_get_contents(HTML_URL);
    $a=preg_match_all("/\(.*?)\<\/span\>/",$html,$b);
    echo $a;
    print_r($b[1]);
    

    $a has hit count, $b[1] the hits

    Tested this against

    
    .. blah ..
    
    
    .. blah ..
    
    always dynamic text A
    always dynamic text B
    always dynamic text C
    
    .. blah ..
    
    
    
    

    and output was

    3
    Array
    (
        [0] => always dynamic text A
        [1] => always dynamic text B
        [2] => always dynamic text C
    )
    

提交回复
热议问题