Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:04:32+00:00 2026-06-17T20:04:32+00:00

from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from manga.items import MangaItem class MangaHere(BaseSpider):

  • 0
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

My goal is to crawl http://www.mangahere.com/seinen or anything on that site. I want to go through every page and collect books that are greater than a 4.5 rating. I started out as a basespider and tried copying and reading the scrapy tutorial but it pretty much went in over my head. I am here to ask what do i do to create my rules, and how. I also cant seem to get my condition to work, the code either only returns the very first item and stops regardless of condition, or grabs everything, again regardless of condition. I know its probably pretty messed up code but I am still struggling to learn. Feel free to touch up the code or offer other advice

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:04:34+00:00Added an answer on June 17, 2026 at 8:04 pm

    Strictly speaking, this isn’t answering the question since my code uses a BaseSpider instead of a CrawlSpider, but it does fulfil the OP’s requirement so…

    Points to note:

    1. Since all of the pagination links aren’t available (you get the first nine and then the last two), I employed a somewhat hacktastic approach. Using the first response in the parse callback, I search for a link with a class of “next” (there’s only one, so have a look to see which link it corresponds to), and then find its immediately preceding sibling. This gives me a handle on the total number of pages in the seinen category (currently 45).
    2. Next, we yield a Request object for the first page to be processed by the parse_item callback.
    3. Then, given that we have determined that there are 45 pages in total, we generate a whole series of Request objects for “./seinen/2.htm” all the way to “./seinen/45.htm”.
    4. Since rating is a list and that its values are floats (which I should have realised on the basis that the condition is 4.5), the way to fix the error encountered is to loop through the list of ratings and cast each item to be a float.

    Anyway, have a look at the following code and see if it makes sense. In theory you should be able to easily extend this code to scrape multiple categories, though that is left as an exercise for the OP. 🙂

    from scrapy.spider import BaseSpider
    from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
    from scrapy.selector import HtmlXPathSelector
    from scrapy.http import Request
    from tutorial.items import MangaItem
    from urlparse import urlparse
    
    class MangaHere(BaseSpider):
        name = "mangah2"
        start_urls = ["http://www.mangahere.com/seinen/"]
        allowed_domains = ["mangahere.com"]
    
        def parse(self, response):
            # get index depth ie the total number of pages for the category
            hxs = HtmlXPathSelector(response)
            next_link = hxs.select('//a[@class="next"]')
            index_depth = int(next_link.select('preceding-sibling::a[1]/text()').extract()[0])
    
            # create a request for the first page
            url = urlparse("http://www.mangahere.com/seinen/")
            yield Request(url.geturl(), callback=self.parse_item)
    
            # create a request for each subsequent page in the form "./seinen/x.htm"
            for x in xrange(2, index_depth):
                pageURL = "http://www.mangahere.com/seinen/%s.htm" % x
                url = urlparse(pageURL)
                yield Request(url.geturl(), callback=self.parse_item)
    
        def parse_item(self,response):
            hxs = HtmlXPathSelector(response)
            sites = hxs.select('//ul/li/div')
            items = []
            for site in sites:
                rating = site.select("p/span/text()").extract()
                for r in rating:
                    if float(r) > 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose this is my code from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from
This is the BaseSpider example from the Scrapy tutorial: from scrapy.spider import BaseSpider from
I am new to Scrapy, I had the spider code class Example_spider(BaseSpider): name =
Here is my spider from scrapy.contrib.spiders import CrawlSpider,Rule from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor from scrapy.selector
I am a newbie. This is my spider: from scrapy.contrib.spiders import CrawlSpider, Rule from
From the Scrapy tutorial: domain_name: identifies the Spider. It must be unique, that is,
from string import join from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor from scrapy.contrib.spiders.crawl import Rule, CrawlSpider from
I did scraping text from webpage using scrapy. In spider, I have code like:
I'm using scrapy and I'm trying to save the scraped data from a spider
Here is my code. My parse_item method is not getting called. from scrapy.contrib.spiders import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.