1
我在學習scrapy,目前我正在試圖解析bbc網站。生成單一鏈接的scrapy規則
我覺得我已經做得很好,但規則只生成一個單一的鏈接。下面是代碼:
class BBCSpider(CrawlSpider):
name = "bbc"
allowed_domains = ["http://www.bbc.com"]
start_urls = [
"http://www.bbc.com/news/world",
]
rules = [
Rule(LinkExtractor(allow=r"http://www.bbc.com/news/world-.*"),
callback='parse_item', follow=True)
]
def parse_item(self, response):
print(response)
目前,只產生一個單一的鏈路(http://www.bbc.com/news/world-middle-east-33833400)。我完全不知道爲什麼。正則表達式匹配頁面上更多的鏈接。
非常感謝。
仍然沒有工作。我嘗試了一堆鏈接來查看正則表達式是否匹配它們,它確實如此。 –
@WebMatrix沒關係,更新。現在適合我。 – alecxe
完美。現在工作。 –