NameError: name 'sel' is not defined

932 views
Skip to first unread message

Sayth Renshaw

unread,
Oct 22, 2013, 7:50:29 AM10/22/13
to scrapy...@googlegroups.com
Hi

I am doing the scrapy tutorial. At the section where we use the interactive shell http://doc.scrapy.org/en/latest/intro/tutorial.html#trying-selectors-in-the-shell
After loading this and checking response.body and response.headers worked I proceeded with the tutorial.

My scrapy version
sayth@sayth-TravelMate-5740G:~/scrapy/tutorial/tutorial$ scrapy --version
Scrapy 0.18.4 - project: tutorial

Issue:

The first step is(what is intended to happen)
In [1]: sel.xpath('//title')
Out[1]: [<Selector (title) xpath=//title>]

What happened to me
In [3]: sel.xpath('//title')
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-7519afbb1d35> in <module>()
----> 1 sel.xpath('//title')

NameError: name 'sel' is not defined

Why am I receiving this error and how can I fix it. I am on Ubuntu 13.10.
Not sure if this is relevant but there is a warning about 'frontend'

/tutorial$ scrapy shell "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"
...
2013-10-22 22:29:26+1100 [default] DEBUG: Crawled (200) <GET http://www.dmoz.org/Computers/Programming/Languages/Python/Books/> (referer: None)
[s] Available Scrapy objects:
[s] hxs <HtmlXPathSelector xpath=None data=u'<html>\r\n<head>\r\n<meta http-equiv="Conten'>
[s] item {}
[s] request <GET http://www.dmoz.org/Computers/Programming/Languages/Python/Books/>
[s] response <200 http://www.dmoz.org/Computers/Programming/Languages/Python/Books/>
[s] settings <CrawlerSettings module=<module 'tutorial.settings' from '/home/sayth/scrapy/tutorial/tutorial/settings.pyc'>>
[s] spider <BaseSpider 'default' at 0x37b9f50>
[s] Useful shortcuts:
[s] shelp() Shell help (print this help)
[s] fetch(req_or_url) Fetch request (or URL) and update local objects
[s] view(response) View response in a browser
/usr/local/lib/python2.7/dist-packages/IPython/frontend.py:30: UserWarning: The top-level `frontend` package has been deprecated. All its subpackages have been moved to the top `IPython` level.
warn("The top-level `frontend` package has been deprecated. "

 
Thanks

Sayth

Paul Tremberth

unread,
Oct 22, 2013, 9:01:32 AM10/22/13
to scrapy...@googlegroups.com
Hi,

You're using Scrapy 0.18.4 so you need to follow

The latest docs and tutorial (http://doc.scrapy.org/en/latest/intro/tutorial.html#trying-selectors-in-the-shell) match Scrapy master branch,
which has unified selectors and many nice things, but it hasn't been released under a tagged version yet.

Hope that helps.
Paul.

Sayth Renshaw

unread,
Oct 22, 2013, 3:33:31 PM10/22/13
to scrapy...@googlegroups.com
It does indeed, I was totally stuck.

Thanks

Sayth

Reply all
Reply to author
Forward
0 new messages