Retrieve Android Market mylibrary with curl

后端 未结 1 1139
北恋
北恋 2020-12-21 19:34

I am trying to retrieve this page using curl in php. This page of course requires you to log in because it displays different apps for each user. I have been following the w

1条回答
  •  星月不相逢
    2020-12-21 20:12

    Here is something I came up with today for this question that has been modified to work for you:

     $value) {
        $post_string .= $key . '=' . urlencode($value) . '&';
    }
    
    $post_string = substr($post_string, 0, -1);
    
    curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
    
    $result = curl_exec($ch); 
    //var_dump($result);
    
    if (preg_match('/^2\d{2}/', curl_getinfo($ch, CURLINFO_HTTP_CODE)) == false) {
        die("Login failed");
        var_dump(curl_getinfo($ch), $result);
    } else {
        curl_setopt($ch, CURLOPT_URL, 'https://market.android.com/mylibrary');
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_HTTPGET, true); 
    
        $result = curl_exec($ch); 
        echo $result;
    }
    
    function getFormFields($data)
    {
        if (preg_match('/(
    )/is', $data, $matches)) { $inputs = getInputs($matches[1]); return $inputs; } else { die('didnt find login form'); } } function getInputs($form) { $inputs = array(); $elements = preg_match_all('/(]+>)/is', $form, $matches); if ($elements > 0) { for($i = 0; $i < $elements; $i++) { $el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]); if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) { $name = $name[1]; $value = ''; if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) { $value = $value[1]; } $inputs[$name] = $value; } } } return $inputs; }

    0 讨论(0)
提交回复
热议问题