Python使用scrapy采集時偽裝成HTTP/1.1的方法
更新時間:2015年04月08日 10:18:35 作者:pythoner
這篇文章主要介紹了Python使用scrapy采集時偽裝成HTTP/1.1的方法,實例分析了scrapy采集的使用技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了Python使用scrapy采集時偽裝成HTTP/1.1的方法。分享給大家供大家參考。具體如下:
添加下面的代碼到 settings.py 文件
復制代碼 代碼如下:
DOWNLOADER_HTTPCLIENTFACTORY = 'myproject.downloader.HTTPClientFactory'
保存以下代碼到單獨的.py文件
復制代碼 代碼如下:
from scrapy.core.downloader.webclient import ScrapyHTTPClientFactory, ScrapyHTTPPageGetter
class PageGetter(ScrapyHTTPPageGetter):
def sendCommand(self, command, path):
self.transport.write('%s %s HTTP/1.1\r\n' % (command, path))
class HTTPClientFactory(ScrapyHTTPClientFactory):
protocol = PageGetter
class PageGetter(ScrapyHTTPPageGetter):
def sendCommand(self, command, path):
self.transport.write('%s %s HTTP/1.1\r\n' % (command, path))
class HTTPClientFactory(ScrapyHTTPClientFactory):
protocol = PageGetter
希望本文所述對大家的Python程序設計有所幫助。
相關文章
python?matplotlib自定義colorbar顏色條及內置色條詳解
由于自己畫圖的需要想要用一些自定義的顏色來做一個colorbar,所以下面這篇文章主要給大家介紹了關于python?matplotlib自定義colorbar顏色條及內置色條的相關資料,需要的朋友可以參考下2022-08-08

