我想抓取一個網站上的一些公共信息(蘋果應用程序的信息)。Python抓取:403和503錯誤
本網站需要登錄才能執行諸如「搜索應用程序/開發者」等操作。雖然有很多網站提供類似的信息,但我認爲這個特定的網站提供了每個應用程序的最完整和詳細的信息。
我作爲一個有效的用戶,能夠執行任務。
但是,當我嘗試通過python代碼訪問信息時,發送POST請求時遇到403錯誤,發送Get請求時遇到504錯誤。
我已經嘗試使用
真實的userAgent頭
假用戶代理」包
FancyOpener [/某物那樣,示出貶值爲Python 3.4]
HttpAuthM .. [/像這樣,對於身份驗證,仍然不起作用]
我猜這個網站很反對自動訪問,但是那裏的詳細信息非常有用。有什麼辦法可以解決這個問題嗎?
謝謝!
我試圖這個頭:
ua = {#'User-Agent':'Mozilla/5.0 (compatible; Googlebot/2.1; +Googlebot - Webmaster Tools Help)',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36',
'Connection':'Keep-Alive',
'Accept-Language':'zh-CN,zh;q=0.8',
'Accept-Encoding':'gzip,deflate,sdch',
'Accept':'*/*',
'Accept-Charset':'GBK,utf-8;q=0.7,*;q=0.3',
'Cache-Control':'max-age=0'
}
------------------------------------------------ HTTPError
Traceback (most recent call last) <ipython-input-43-421b27c5194e> in <module>()
68 data= data.encode('utf-8')
69 request = urq.Request(url, data, headers = ua)
---> 70 response = urq.urlopen(request)
71 the_page = response.read()
72 print(the_page)
c:\python34\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
159 else:
160 opener = _opener
--> 161 return opener.open(url, data, timeout)
162
163 def install_opener(opener):
c:\python34\lib\urllib\request.py in open(self, fullurl, data, timeout)
468 for processor in self.process_response.get(protocol, []):
469 meth = getattr(processor, meth_name)
--> 470 response = meth(req, response)
471
472 return response
c:\python34\lib\urllib\request.py in http_response(self, request, response)
578 if not (200 <= code < 300):
579 response = self.parent.error(
--> 580 'http', request, response, code, msg, hdrs)
581
582 return response
c:\python34\lib\urllib\request.py in error(self, proto, *args)
506 if http_err:
507 args = (dict, 'default', 'http_error_default') + orig_args
--> 508 return self._call_chain(*args)
509
510 # XXX probably also want an abstract factory that knows when it makes
c:\python34\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
440 for handler in handlers:
441 func = getattr(handler, meth_name)
--> 442 result = func(*args)
443 if result is not None:
444 return result
c:\python34\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
586 class HTTPDefaultErrorHandler(BaseHandler):
587 def http_error_default(self, req, fp, code, msg, hdrs):
--> 588 raise HTTPError(req.full_url, code, msg, hdrs, fp)
589
590 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: FORBIDDEN
----------------------------------------------
的下面結果我通過使用 「高級REST客戶端」,這是一種鉻擴展發送請求獲得。請注意,在不需要登錄的頁面上,代碼是200;另一次是在403以下
[接入成功在評論登錄page.See鏈接[3]
[訪問失敗] [4]
嗨@nonsensei,我可以問一個正確模擬的請求和會話的樣本嗎?我曾嘗試過這個標題,但仍然失敗。你能指點我什麼問題嗎? – KeepLearning
對不起,請參閱編輯後。我嘗試在評論中張貼,但太難閱讀 – KeepLearning
有可能是隱藏的字段或缺少標題,你可以發佈你的代碼和鏈接到非工作頁面? 你忘主機頭 – nonsensei