Reputation: 131
I'm writing a crawler to get some pages from Yelp. I define the Yelp Item like this:
yelpItem.py
:
import scrapy
class YelpItem(scrapy.Item):
# define the fields for your item here like:
name = scrapy.Field()
link = scrapy.Field()
and in the spider folder, I use YelpItem
in the parse
function.
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//h3/span/a[contains(@class, "biz-name")]')
items = []
for site in sites:
item = YelpItem()
When running it, it says:
NameError: global name 'YelpItem' is not defined
I had searched several webpages, and tried to add codes like:
from hw1.items import YelpItem
(hw1 is my project name),but it is not helping. This will leads to an error like: No module named items
Can anyone help me to figure out how to deal with this? Thanks!
Upvotes: 2
Views: 3144