我試圖廢棄某些類「後項目後項目xxxxx」的鏈接。但由於每個班級都不同,我怎樣才能抓住他們呢?Scrapy查找具有不同(類似)類的所有鏈接
<li class="post-item post-item-18887"><a
href="http://example.com/archives/18887.html" title="Post1"</a></li>
<li class="post-item post-item-18883"><a href="http://example.com/archives/18883.html" title="Post2"</a></li>
我的代碼:
廢料所有的網吧來自example.com
class DengaSpider(scrapy.Spider):
name = 'cafes'
allowed_domains = ['example.com']
start_urls = [
'http://example.com/archives/8136.html',
]
rules = [
Rule(
LinkExtractor(
allow=('^http://example\.com/archives/\d+.html$'),
unique=True
),
follow=True,
callback="parse_items"
)
]
def parse(self, response):
cafelink = response.css('post.item').xpath('//a/@href').extract()
if cafelink is not None:
print(cafelink)
鏈接的CSS部分不能正常工作,我該如何解決?
// *給我語法錯誤,嘗試了幾種不同的方式仍然是一樣的錯誤 – DatCra
對不起,忘了引號,編輯我的答案修復它 – rrschmidt