Pyspider的參數

url :

the url or url list to be crawled.
爬行url或url列表。

callback:

the method to parse the response. _default: call _
該方法解析響應。

def on_start(self):
    self.crawl('http://scrapy.org/', callback=self.index_page)

age:

the period of validity of the task. The page would be regarded as not modified during the period. default: -1(never recrawl)
有效期內的任務。該頁面將被視為不修改期間。默認值:1(從來沒有重新抓取)

@config(age=10 * 24 * 60 * 60)
def index_page(self, response):
    ...
priority:

the priority of task to be scheduled, higher the better. default: 0
要調度的任務的優先級,高越好。默認值:0

def index_page(self):
    self.crawl('http://www.example.org/page2.html', callback=self.index_page)
    self.crawl('http://www.example.org/233.html', callback=self.detail_page,
               priority=1)
exetime:

the executed time of task in unix timestamp. default: 0(immediately)
任務的執行時間在unix時間戳。默認值:0(馬上)

import time
def on_start(self):
    self.crawl('http://www.example.org/', callback=self.callback,
               exetime=time.time()+30*60)
retries:

retry times while failed. default: 3
重試次數而失敗了。默認值:3

itag:

a marker from frontier page to reveal the potential modification of the task. It will be compared to its last value, recrawl when it's changed. default: None

從邊境頁面標記揭示潛在的修改任務。這將是最后的價值相比,重新抓取的時候改變了。默認值:無

def index_page(self, response):
    for item in response.doc('.item').items():
        self.crawl(item.find('a').attr.url, callback=self.detail_page,
                   itag=item.find('.update-time').text())
auto_recrawl:

when enabled, task would be recrawled every age time. default: False
當啟用,任務將會重新抓取每個時代。默認值:假

def on_start(self):
    self.crawl('http://www.example.org/', callback=self.callback,
               age=5*60*60, auto_recrawl=True)
method:

HTTP method to use. default: GET
使用HTTP方法。違約:

params:

dictionary of URL parameters to append to the URL.
字典的URL參數附加到URL。

def on_start(self):
    self.crawl('http://httpbin.org/get', callback=self.callback,
               params={'a': 123, 'b': 'c'})
    self.crawl('http://httpbin.org/get?a=123&b=c', callback=self.callback)
data:

the body to attach to the request. If a dictionary is provided, form-encoding will take place.
身體附加到請求。如果提供了字典,form-encoding將發生。

def on_start(self):
    self.crawl('http://httpbin.org/post', callback=self.callback,
               method='POST', data={'a': 123, 'b': 'c'})
files:

dictionary of {field: {filename: 'content'}} files to multipart upload.
{領域的詞典:{文件名:‘內容’} }文件多部分upload.”

user_agent:

the User-Agent of the request
用戶代理的請求

headers:

dictionary of headers to send.
字典的頭來發送。

cookies:

dictionary of cookies to attach to this request.
字典的餅干附著這個請求。

connect_timeout:

timeout for initial connection in seconds. default: 20
首次連接超時秒。默認值:20

timeout:

maximum time in seconds to fetch the page. default: 120
最長時間以秒為單位獲取頁面。默認值:120

allow_redirects:

follow 30x redirect default: True
遵循30 x定向違約:真的

validate_cert:

For HTTPS requests, validate the server’s certificate? default: True
HTTPS請求,驗證服務器的證書嗎?默認值:真正的

proxy

proxy server of username:password@hostname:port to use, only http proxy is supported currently.
代理服務器的用戶名:password@hostname:端口使用,目前只支持http代理。

class Handler(BaseHandler):
    crawl_config = {
        'proxy': 'localhost:8080'
    }
etag

use HTTP Etag mechanism to pass the process if the content of the page is not changed. default: True
使用HTTP Etag機制通過這個過程如果頁面的內容沒有改變。默認值:真正的

last_modified

use HTTP Last-Modified header mechanism to pass the process if the content of the page is not changed. default: True
使用HTTP last - modified頭機制通過這個過程如果頁面的內容沒有改變。默認值:真正的

fetch_type

set to js to enable JavaScript fetcher. default: None
將js啟用JavaScript取物。默認值:無

js_script

JavaScript run before or after page loaded, should been wrapped by a function like function() { document.write("binux"); }.
JavaScript運行之前或之后頁面加載,應該被包裝函數函數(){ document . write(“binux”);}。

def on_start(self):
    self.crawl('http://www.example.org/', callback=self.callback,
               fetch_type='js', js_script='''
               function() {
                   window.scrollTo(0,document.body.scrollHeight);
                   return 123;
               }
               ''')
js_run_at

run JavaScript specified via js_script at document-start or document-end. default: document-end
通過指定運行JavaScript js_script document-start或document-end。默認值:document-end

js_viewport_width/js_viewport_height

set the size of the viewport for the JavaScript fetcher of the layout process.
設置窗口的大小的JavaScript取物的布局過程。

load_images

load images when JavaScript fetcher enabled. default: False
當啟用JavaScript訪問者載入圖像。默認值:假

save

a object pass to the callback method, can be visit via response.save.
 一個對象傳遞給回調方法,可以通過response.save訪問。

def on_start(self):
    self.crawl('http://www.example.org/', callback=self.callback,
               save={'a': 123})

def callback(self, response):
    return response.save['a']
taskid

unique id to identify the task, default is the MD5 check code of the URL, can be overridden by method def get_taskid(self, task)
惟一的id來識別任務,默認URL的MD5校驗碼,可以覆蓋方法def get_taskid(自我,任務)

import json
from pyspider.libs.utils import md5string
def get_taskid(self, task):
    return md5string(task['url']+json.dumps(task['fetch'].get('data', '')))
force_update

force update task params even if the task is in ACTIVE status.
力更新任務params即使任務處于活動狀態。

cancel

cancel a task, should be used with force_update to cancel a active task. To cancel an auto_recrawl task, you should set auto_recrawl=False as well.
取消任務,應該使用force_update取消活動任務。取消auto_recrawl任務,你應該設定auto_recrawl = False。

cURL command

self.crawl(curl_command)
cURL is a command line tool to make a HTTP request. It can easily get form Chrome Devtools > Network panel, right click the request and "Copy as cURL".
旋度是一個命令行工具做一個HTTP請求。它可以很容易地形成鉻Devtools >網絡面板中,右鍵單擊請求和“復制為旋度”。
You can use cURL command as the first argument of self.crawl. It will parse the command and make the HTTP request just like curl do.
您可以使用cURL命令self.crawl的第一個參數。它將解析命令和HTTP請求和旋度一樣。

@config(**kwargs)

default parameters of self.crawl when use the decorated method as callback. For example:
默認參數的自我。爬行時使用裝飾方法的回調

@config(age=15*60)
def index_page(self, response):
    self.crawl('http://www.example.org/list-1.html', callback=self.index_page)
    self.crawl('http://www.example.org/product-233', callback=self.detail_page)

@config(age=10*24*60*60)
def detail_page(self, response):
    return {...}
Handler.crawl_config = {}

default parameters of self.crawl for the whole project.
The parameters in crawl_config for scheduler (priority, retries, exetime, age, itag, force_update, auto_recrawl, cancel) will be joined when the task created, the parameters for fetcher and processor will be joined when executed.
You can use this mechanism to change the fetch config (e.g. cookies) afterwards.

默認參數的自我。爬行對于整個項目。
crawl_config的參數調度器(優先級、重試exetime,年齡,itag,force_update,auto_recrawl,取消)將加入任務創建時,參數的取物和處理器執行時將加入。
您可以使用這種機制改變獲取配置(如餅干)。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,461評論 6 532
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,538評論 3 417
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 176,423評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,991評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,761評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,207評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,268評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,419評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,959評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,653評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,901評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,678評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,978評論 2 374

推薦閱讀更多精彩內容