簡體   English   中英

使用 requests.get() python 時出現 403 錯誤

[英]getting 403 error while using requests.get() python

在獲得幾個響應后請求多個 URL 時,它開始為其他 URL 提供 403 錯誤。

我嘗試使用用戶代理和代理仍然存在問題。 我也嘗試了 0.5 秒的延遲。

我正在使用 - 請求版本 = 2.22.0

這是它的樣子

這是 (r.status_code, r.headers, r.text) 的樣子:

403 {'Allow': 'GET, POST, HEAD, PUT, PATCH, DELETE, OPTIONS', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html; charset=UTF-8', 'Accept-Ranges': 'bytes, bytes, bytes, bytes', 'Content-Length': '1519', 'Date': 'Thu, 06 Feb 2020 10:34:40 GMT', 'Connection': 'keep-alive', 'set-cookie': 'machine_cookie=9581501972230; expires=Wed, 05 Feb 2025 10:34:40 GMT; path=/;', 'X-Served-By': 'cache-sea4466-SEA, cache-maa18327-MAA', 'X-Cache': 'MISS, MISS', 'X-Cache-Hits': '0, 0', 'X-Timer': 'S1580985280.913451,VS0,VE312', 'Vary': 'User-Agent, Accept-Encoding'} <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Access to this page has been denied.</title>
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
  <style>
    html, body {
      margin: 0;
      padding: 0;
      font-family: 'Open Sans', sans-serif;
      color: #000;
    }

    .container {
      align-items: center;
      display: flex;
      flex: 1;
      justify-content: space-between;
      flex-direction: column;
      height: 100%;
    }

    .container > div {
      width: 100%;
      display: flex;
      justify-content: center;
    }

    .container > div > div {
      display: flex;
      width: 80%;
    }

    .customer-logo-wrapper {
      padding-top: 2rem;
      flex-grow: 0;
      background-color: #fff;
    }

    .customer-logo {
      border-bottom: 1px solid #000;
    }

    .customer-logo > img {
      padding-bottom: 1rem;
      max-height: 50px;
      max-width: 100%;
    }

    .page-title-wrapper {
      flex-grow: 0;  /* was 2, but that pushed it too far down the page */
    }

    .page-title {
      flex-direction: column-reverse;
    }

    .content-wrapper {
      flex-grow: 5;
    }

    .content {
      flex-direction: column;
    }

    @media (min-width: 768px) {
      html, body {
        height: 100%;
      }
    }
  </style>
  <script>
    window._pxAppId = 'PXxgCxM9By';
    window._pxJsClientSrc = '/xgCxM9By/init.js';
    window._pxHostUrl = '/xgCxM9By/xhr';

    startTime = Date.now();
    window._pxOnCaptchaSuccess = function(isValid){
      var solutionTime = Math.floor((Date.now() - startTime) / 1000);
      var reload = function(){ top.location.reload(); };
      sendEvent("captcha/solved?px_uuid=" + window._pxUuid + "&time_to_solution=" + solutionTime + '&isValid=' + isValid, reload);
      setTimeout(reload, 700);
    };

    function sendEvent(event, onload){
      var xhr = new XMLHttpRequest();
      xhr.open("GET", "/_sa_track/" + event);
      if (onload) xhr.addEventListener("load", onload);
      xhr.send();
    }
  </script>
<script type="text/javascript">window._pxVid = "";window._pxUuid = "47a70d80-48cc-11ea-860b-c96869955a6b";</script></head>
<body>
<section class="container">
  <div class="page-title-wrapper">
    <div class="page-title">
      <h1>Please click “I am not a robot” to continue</h1>
    </div>
  </div>
  <div class="content-wrapper">
    <div class="content">
      <div id="px-captcha"></div>
      <p></p>
      <p>
        To ensure this doesn’t happen in the future, please enable Javascript and cookies in your browser.<br/>
        Is this happening to you frequently? Please <a href="https://seekingalpha.userecho.com?source=captcha">report it on our feedback forum</a>.
      </p>
      <p>
        If you have an ad-blocker enabled you may be blocked from proceeding. Please disable your ad-blocker and refresh.
      </p>
      <p>Reference ID: <span id="refid"></span></p>
    </div>
  </div>
  <script>
    document.getElementById("refid").innerHTML = window._pxUuid;
    sendEvent("captcha/shown?px_uuid=" + window._pxUuid);
  </script>
</section>

<script src="/xgCxM9By/captcha/PXxgCxM9By/captcha.js?a=c&m=0"></script>

</body>
</html>

服務器通過顯示403 Forbidden HTTP 狀態代碼和驗證碼來防止您獲取所需信息,以確保請求是由人發起的,而不是由 Python 腳本發起的。 遠程服務很可能暫時禁止您的會話或您的 IP 地址。

有一些變通方法可以避免從服務器上進行此類禁止,但不能保證您可以克服該限制

所以我只能給你一些建議:

  1. 最好使用Session而不是一次性請求,因為它保留了請求之間的狀態。
  2. 像瀏覽器一樣使用 User-Agent。
  3. 適度增加請求之間的冷卻時間。
  4. 代理也可以被遠程服務器禁止(通常基於其 IP),所以有時在循環模式下使用多個代理是個好主意。
  5. 您的主要目標是使您的請求看起來像來自普通瀏覽器的請求。 您可以在開發人員選項卡中檢查從瀏覽器到遠程服務器的請求。 嘗試復制瀏覽器的行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM