本文實例講述了Python使用scrapy采集時偽裝成HTTP/1.1的方法。分享給大家供大家參考。具體如下:
添加下面的代碼到 settings.py 文件
保存以下代碼到單獨的.py文件
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程序設計有所幫助。