Simple html dom file_get_html not working - is there any workaround?

后端 未结 4 2015
独厮守ぢ
独厮守ぢ 2020-11-29 06:04


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 06:52

    As I said, your example is working fine for me... But try this way using curl instead:

    //base url
    $base = 'https://play.google.com/store/apps';
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_URL, $base);
    curl_setopt($curl, CURLOPT_REFERER, $base);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    $str = curl_exec($curl);
    curl_close($curl);
    
    // Create a DOM object
    $html_base = new simple_html_dom();
    // Load HTML from a string
    $html_base->load($str);
    
    //get all category links
    foreach($html_base->find('a') as $element) {
        echo "
    ";
        print_r( $element->href );
        echo "
    "; } $html_base->clear(); unset($html_base);

    It gets all the links as expected:

    enter image description here

    And make sure you have php_openssl and php_curl installed...

提交回复
热议问题