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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:38:38+00:00 2026-06-17T21:38:38+00:00

I am new to Scrapy and really python as well. I am trying to

  • 0

I am new to Scrapy and really python as well. I am trying to write a scraper that will extract article title, link and article description ALMOST like an RSS feed from a web page to help me with my thesis. I’ve written the following scraper and when I run it and export it as a .txt it comes back blank. I believe I need to add in an Item Loader but I am not positive.

Items.py

from scrapy.item import Item, Field

class NorthAfricaItem(Item):
    title = Field()
    link = Field()
    desc = Field()
    pass

Spider

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from northafricatutorial.items import NorthAfricaItem

class NorthAfricaItem(BaseSpider):
   name = "northafrica"
   allowed_domains = ["http://www.north-africa.com/"]
   start_urls = [
       "http://www.north-africa.com/naj_news/news_na/index.1.html",
   ]

 def parse(self, response):
 hxs = HtmlXPathSelector(response)
 sites = hxs.select('//ul/li')
 items = []
 for site in sites:
     item = NorthAfricaItem()
     item['title'] = site.select('a/text()').extract()
     item['link'] = site.select('a/@href').extract()
     item['desc'] = site.select('text()').extract()
     items.append(item)
 return items

UPDATE

Thanks to Talvalin for the help and additionally with some messing around I was able to fix the problem. I was using a stock script that I found online. However once I utilized the shell I was able to find the correct tags to get what I needed. Ive ended up with:

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from northafrica.items import NorthAfricaItem

class NorthAfricaSpider(BaseSpider):
   name = "northafrica"
   allowed_domains = ["http://www.north-africa.com/"]
   start_urls = [
       "http://www.north-africa.com/naj_news/news_na/index.1.html",
   ]

   def parse(self, response):
       hxs = HtmlXPathSelector(response)
       sites = hxs.select('//ul/li')
       items = []
       for site in sites:
           item = NorthAfricaItem()
           item['title'] = site.select('//div[@class="short_holder"]    /h2/a/text()').extract()
       item['link'] = site.select('//div[@class="short_holder"]/h2/a/@href').extract()
       item['desc'] = site.select('//span[@class="summary"]/text()').extract()
       items.append(item)
   return items

If anyone sees anything here I did wrong let me know……but it works.

  • 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-17T21:38:39+00:00Added an answer on June 17, 2026 at 9:38 pm

    The thing to note about this code is that it runs with an error. Try running the spider via the command line and you will see something along the lines of:

            exceptions.TypeError: 'NorthAfricaItem' object does not support item assignment
    
    2013-01-24 16:43:35+0000 [northafrica] INFO: Closing spider (finished)
    

    The reason why this error is occurring is because you’ve given your spider and your item classes the same name: NorthAfricaItem

    In your spider code, when you create an instance of NorthAfricaItem to assign things to (like title, link and desc), the spider version takes precedence over the item version. Since the spider version of NorthAfricaItem is not actually a type of Item, the item assignment fails.

    To fix the issue, rename your spider class to something like NorthAfricaSpider and the problem should be resolved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really new to python, just played around with the scrapy framework that
This is the code for Spyder1 that I've been trying to write within Scrapy
I am relatively new to using Scrapy or python for that matter. I am
I'm new with using scrapy and i'm trying to get some info from a
I am new to python and scrapy and hence am getting some basic doubts(please
I am pretty new to Php and I try to write some code that
New to Python and Scrapy. I need these modules apparently to run scrapy properly.
I am new in python.I installed scrapy but it giving error importerror no module
I am reasonably new to the inner workings of Python. I have been trying
I'm using Ruby 1.9.3 and trying to write a Google Play scraper loosely based

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.