I am trying to crawl a website using scrapy and storing the scraped data into variables of item class

Yogesh D

I have a spider file dmoz_spider.py and it contets are:

    from scrapy.spider import Spider
    from scrapy.selector import Selector
    from dmoz.items import DmozItem


    class DmozSpider(Spider):
       name = "dmoz"
       allowed_domains = ["m.timesofindia.com"]
       start_urls = ["http://m.timesofindia.com/india/Congress-BJP-spar-over-Gujarat-govts-Rs-11-per-day-poverty-line/articleshow/29830237.cms"]

       def parse(self, response):
            sel = Selector(response)
                torrent = DmozItem()
                filename = response.url.split("/")[-2]+"1.txt"
            torrent['link']  = response.url
            torrent['title']  = sel.xpath("//h1/text()").extract() 
                open(filename, 'wb').write(torrent['link'])

2nd file is items.py

   from scrapy.item import Item, Field

     class DmozItem(Item):
        title = Field()
        link = Field()
        desc = Field()

I am getting following error on command line when i run my crawler...

ImportError: No module named dmoz.items

as to when i removed the import statement from my spider file it gave me error saying

exceptions.NameError: global name 'DmozItem' is not defined

Yogesh D

found the problem to my question and posting it so that if any one ends up on the similar problem he can get the answer.

in my code where I am doing this

 from dmoz.items import DmozItem

it should actually be

 from tutorial.items import DmozItem or

 from tutorial.items import *

since my project directory or package name is tutorial That was the mistake I was doing earlier.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I am trying to crawl a website using scrapy and storing the scraped data into variables of item class

From Dev

I am using Scrapy to crawl data, but the server block my IP

From Dev

Web Scrapy!! How can I crawl using Click event data?

From Dev

Data not scraped in XML or JSON using scrapy

From Dev

Trying to access the instance variables of the class that I am calling a class method on

From Dev

Scrapy: Associate scraped data from different links to 1 Item/Model

From Dev

Scrapy crawl pages but doesn't scraped items

From Dev

How to simulate xhr request using Scrapy when trying to crawl data from an ajax-based webstie?

From Dev

crawl dynamic webpage for data using scrapy

From Dev

Storing scraped data into the database sqlite

From Dev

How to save crawl page link into item using scrapy?

From Dev

Scrapy crawl only part of a website

From Dev

Data not properly being scraped from a given website using python

From Dev

scrapy scraped data contains javascript

From Dev

crawl pages using scrapy

From Dev

Scrapy - How to crawl new pages based on links in scraped items

From Dev

Taking data from multiple links while storing in one item in Scrapy

From Dev

I am trying to show an AlertDialog when a ListView item is clicked within the Adapter class, but a black screen is covering the dialog

From Dev

I am trying to load variables in an array

From Dev

I am trying to copy an variables into an array

From Dev

I am trying to copy an variables into an array

From Dev

Scrapy can not crawl link - comment of vnexpress website

From Dev

Crawl news website from rss with scrapy

From Dev

get python UnicodeEncodeError when i was using selenium to crawl a website

From Dev

Scrapy crawl and extract data into mysql

From Dev

Crawl data with Scrapy to load more?

From Dev

scrapy, I am trying to remove empty lines that are extracted to a csv file

From Dev

scrapy, I am trying to remove empty lines that are extracted to a csv file

From Dev

Storing my output scraped from website into an array and printing specific part of it

Related Related

  1. 1

    I am trying to crawl a website using scrapy and storing the scraped data into variables of item class

  2. 2

    I am using Scrapy to crawl data, but the server block my IP

  3. 3

    Web Scrapy!! How can I crawl using Click event data?

  4. 4

    Data not scraped in XML or JSON using scrapy

  5. 5

    Trying to access the instance variables of the class that I am calling a class method on

  6. 6

    Scrapy: Associate scraped data from different links to 1 Item/Model

  7. 7

    Scrapy crawl pages but doesn't scraped items

  8. 8

    How to simulate xhr request using Scrapy when trying to crawl data from an ajax-based webstie?

  9. 9

    crawl dynamic webpage for data using scrapy

  10. 10

    Storing scraped data into the database sqlite

  11. 11

    How to save crawl page link into item using scrapy?

  12. 12

    Scrapy crawl only part of a website

  13. 13

    Data not properly being scraped from a given website using python

  14. 14

    scrapy scraped data contains javascript

  15. 15

    crawl pages using scrapy

  16. 16

    Scrapy - How to crawl new pages based on links in scraped items

  17. 17

    Taking data from multiple links while storing in one item in Scrapy

  18. 18

    I am trying to show an AlertDialog when a ListView item is clicked within the Adapter class, but a black screen is covering the dialog

  19. 19

    I am trying to load variables in an array

  20. 20

    I am trying to copy an variables into an array

  21. 21

    I am trying to copy an variables into an array

  22. 22

    Scrapy can not crawl link - comment of vnexpress website

  23. 23

    Crawl news website from rss with scrapy

  24. 24

    get python UnicodeEncodeError when i was using selenium to crawl a website

  25. 25

    Scrapy crawl and extract data into mysql

  26. 26

    Crawl data with Scrapy to load more?

  27. 27

    scrapy, I am trying to remove empty lines that are extracted to a csv file

  28. 28

    scrapy, I am trying to remove empty lines that are extracted to a csv file

  29. 29

    Storing my output scraped from website into an array and printing specific part of it

HotTag

Archive