今天在爬取一個朝鮮網站:http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=2時,發現它會重定向多次,又回到原url,如果scrapy過濾重復url,則無法爬取。
所以,查資料發現:可以重復爬取,而且設置比較簡單。
資料如下:
https://blog.csdn.net/huyoo/article/details/75570668
實際代碼如下:
def parse(self, response):
meta = response.meta
===================================================================================
meta["website"] = "http://www.rodong.rep.kp/ko/"
meta['area'] = 'xj_rodong_rep_kp'
start_url_list = [
# "http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=3",
# "http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=5",
# "http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=6",
# "http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=7",
# "http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=1&iSubMenuID=1",
"http://www.rodong.rep.kp/cn/index.php?strPageID=SF01_01_02&iMenuID=2"
]
for url in start_url_list:
yield Request(url, meta=meta, callback=self.parse_list, dont_filter=True)