2014-02-25 46 views
2

我有一個起始網址,只需要爬一個頁面,但我想通過在START_URL輸入1和50之間的隨機數隨機選擇一個頁面:Scrapy單START_URL隨機數

start_urls = ["http://www.modcloth.com/shop/bedding?sorting=loved&page=1"] 

where page =隨機數

回答

4

您可以使用標準的random.randint庫函數。

from random import randint 

start_urls = ["http://www.modcloth.com/shop/bedding?sorting=loved" 
       "&page={0}".format(randint(1,50))]