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 8403117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:15:32+00:00 2026-06-09T22:15:32+00:00

I am trying to do: class SpiderSpider(CrawlSpider): name = lolies allowed_domains = [domain.com] start_urls

  • 0

I am trying to do:

class SpiderSpider(CrawlSpider):
    name = "lolies"
    allowed_domains = ["domain.com"]
    start_urls = ['http://www.domain.com/directory/lol2']
    rules = (Rule(SgmlLinkExtractor(allow=[r'directory/lol2/\w+$']), follow=True), Rule(SgmlLinkExtractor(allow=[r'directory/lol2/\w+/\d+$']), follow=True),Rule(SgmlLinkExtractor(allow=[r'directory/lol2/\d+$']), callback=self.parse_loly))

def parse_loly(self, response):
    print 'Hi this is the loly page %s' % response.url
    return

That returns me:

NameError: name 'self' is not defined

If I change callback to callback="self.parse_loly" seems never to be called and print the URL.

But seems to be crawling the sites with no problems because I get many Crawled 200 debug messages for that rule.

What could I be doing wrong?

Thanks in advance guys!

  • 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-09T22:15:33+00:00Added an answer on June 9, 2026 at 10:15 pm

    It looks like the whitespace for parse_loly is not aligned correctly. Python is whitespace sensitive so to the interpreter it looks like a method outside of SpiderSpider.

    You might also want to split your rules line into shorter lines as per PEP8.

    Try this:

    from scrapy.contrib.spiders import CrawlSpider, Rule
    from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
    
    class SpiderSpider(CrawlSpider):
        name = "lolies"
        allowed_domains = ["domain.com"]
        start_urls = ['http://www.domain.com/directory/lol2/']
        rules = (
            Rule(SgmlLinkExtractor(allow=('\w+$', ))), 
            Rule(SgmlLinkExtractor(allow=('\w+/\d+$', ))),
            Rule(SgmlLinkExtractor(allow=('\d+$',)), callback='parse_loly'),
        )
    
        def parse_loly(self, response):
            print 'Hi this is the loly page %s' % response.url
            return None
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create Class Table Inheritance as in ( http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html ) So let's
I am trying to get class name with the extension (e.g. Employee.cs or Employee.aspx.cs)
I'm trying to add class name in my Concrete 5 theme. What's the elegant
I am trying pass class as value in hashmap. I need to get the
I am trying to create class properties for each element in an array. The
i am trying to add class on on-click jquery event for that i am
I'm trying to add class visible to a div with the same ID as
I am trying to write class that inherits from FMX TStyledControl. When style is
I'm trying to implement class inheritance hieararchy with NHibernate and SQL server. I made
I am trying to use Class::DBI with Catalyst::Plugin::Authentication::Store::DBIC. The example given on CPAN does

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.