3
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from manga.items import MangaItem
class MangaHere(BaseSpider):
name = "mangah"
allowed_domains = ["mangahere.com"]
start_urls = ["http://www.mangahere.com/seinen/"]
def parse(self,response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//ul/li/div')
items = []
for site in sites:
rating = site.select("p/span/text()").extract()
if rating > 4.5:
item = MangaItem()
item["title"] = site.select("div/a/text()").extract()
item["desc"] = site.select("p[2]/text()").extract()
item["link"] = site.select("div/a/@href").extract()
item["rate"] = site.select("p/span/text()").extract()
items.append(item)
return items
我的目標是抓取www.mangahere.com/seinen或該網站上的任何內容。我想瀏覽每一頁並收集大於4.5分的書籍。我最初是作爲一個基地蜘蛛,並試圖複製和閱讀scrapy教程,但它幾乎讓我感到頭疼。我在這裏問我該如何創建我的規則,以及如何做。我似乎也無法讓自己的條件起作用,代碼或者只返回第一個條目,無論條件如何都會停下來,或者不管條件如何都會抓取所有內容。我知道它可能很糟糕的代碼,但我仍然努力學習。隨意摸了代碼或提供其他建議我如何爲使用scrapy的爬行器創建規則
ahhh這是有道理的,我試過浮動(評級),但沒有工作出於某種原因,謝謝。我會重新測試代碼,並返回結果 – gallly
它說我不能將評級變成一個整數,因爲它是一個列表,我如何使它不返回一個列表? – gallly
非常感謝您的幫助! – gallly