解決Python爬蟲錯誤之twisted.web.error.SchemeNotSupported: Unsupported scheme: b''
Python爬蟲錯誤twisted.web.error.SchemeNotSupported: Unsupported scheme: b''
在使用scrapy爬蟲時,出現(xiàn)了下面了的錯誤
Traceback (most recent call last):
File "E:\project\venv\lib\site-packages\twisted\internet\defer.py", line 1416, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "E:\project\venv\lib\site-packages\twisted\python\failure.py", line 491, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "E:\project\venv\lib\site-packages\scrapy\core\downloader\middleware.py", line 43, in process_request
defer.returnValue((yield download_func(request=request,spider=spider)))
File "E:\project\venv\lib\site-packages\scrapy\utils\defer.py", line 45, in mustbe_deferred
result = f(*args, **kw)
File "E:\project\venv\lib\site-packages\scrapy\core\downloader\handlers\__init__.py", line 65, in download_request
return handler.download_request(request, spider)
File "E:\project\venv\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 67, in download_request
return agent.download_request(request)
File "E:\project\venv\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 331, in download_request
method, to_bytes(url, encoding='ascii'), headers, bodyproducer)
File "E:\project\venv\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 252, in request
proxyEndpoint = self._getEndpoint(self._proxyURI)
File "E:\project\venv\lib\site-packages\twisted\web\client.py", line 1635, in _getEndpoint
return self._endpointFactory.endpointForURI(uri)
File "E:\project\venv\lib\site-packages\twisted\web\client.py", line 1513, in endpointForURI
raise SchemeNotSupported("Unsupported scheme: %r" % (uri.scheme,))
twisted.web.error.SchemeNotSupported: Unsupported scheme: b''
原因
經(jīng)調(diào)查是在下載中間件中設(shè)置代理是出現(xiàn)了錯誤:
class IpProxyDownloadMiddleware(object):
PROXIES = ['110.52.235.131:9999','110.52.235.249:9999','112.17.38.141:3128']
def process_request(self,request,spider):
proxy = random.choice(self.PROXIES)
request.meta['proxy'] = proxy解決
在上面的下載中間件中設(shè)置代理時,需要添加協(xié)議名稱,“http://”或者“https://”。
如下:
class IpProxyDownloadMiddleware(object):
PROXIES = ['110.52.235.131:9999','110.52.235.249:9999','112.17.38.141:3128']
def process_request(self,request,spider):
proxy = random.choice(self.PROXIES)
request.meta['proxy'] = 'http://'+proxy問題成功解決。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python?內(nèi)置模塊?argparse快速入門教程
argparse模塊是Python內(nèi)置的用于命令項選項與參數(shù)解析的模塊,argparse模塊可以讓人輕松編寫用戶友好的命令行接口,能夠幫助程序員為模型定義參數(shù),這篇文章主要介紹了快速入門Python內(nèi)置模塊argparse,需要的朋友可以參考下2023-06-06
Python中selenium實現(xiàn)文件上傳所有方法整理總結(jié)
本篇文章主要介紹了Python中selenium實現(xiàn)文件上傳所有方法整理總結(jié),具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-04-04
Python統(tǒng)計列表元素出現(xiàn)次數(shù)的方法示例
這篇文章主要介紹了Python統(tǒng)計列表元素出現(xiàn)次數(shù)的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-04-04
Python中的Numeric包和Numarray包使用教程
這篇文章主要介紹了Python中的Numeric包和Numarray包使用教程,來自IBM官方網(wǎng)站上的技術(shù)文檔,需要的朋友可以參考下2015-04-04
Pandas基礎(chǔ)使用指南之排序、字符串日期處理和文件合并拆分技巧
這篇文章主要為大家簡單介紹了Pandas一些基礎(chǔ)使用,包括排序,字符串日期處理和文件合并拆分等技巧,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下2026-01-01
Python使用BeautifulSoup解析并獲取圖片的實戰(zhàn)分享
這篇文章主要介紹了Python使用BeautifulSoup解析并獲取圖片的實戰(zhàn)分享,文中通過代碼和圖文結(jié)合的方式給大家講解的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下2024-06-06

