How to pass Age Verification with DOM

前端 未结 2 1165
天命终不由人
天命终不由人 2021-01-19 02:19

I\'m attempting to pull some image URLs from Steam store pages, such as: http://store.steampowered.com/app/35700/
http://store.steampowered.com/app/252490/

Her

2条回答
  •  没有蜡笔的小新
    2021-01-19 02:27

    Solved! Here's the working code:

    $url = 'http://store.steampowered.com/app/35700/';
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_COOKIE, "birthtime=28801; path=/; domain=store.steampowered.com");
    curl_setopt($ch, CURLOPT_TIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $result = curl_exec($ch);
    
    $dom = new domDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($result);
    $dom->preserveWhiteSpace = false;
    
    $images = $dom->getElementsByTagName('img');
    foreach ($images as $image) {
      $src = $image->getAttribute('src');
      echo $src.PHP_EOL;
    }
    
    curl_close($ch);
    

提交回复
热议问题