How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.
Rustom Mody
rustompmody at gmail.com
Thu May 15 08:17:57 EDT 2014
On Thursday, May 15, 2014 4:55:42 PM UTC+5:30, Simon Evans wrote:
> Dear Programmers,
>
> As anticipated, it has not been to long before I have encountered further
>
> difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it
>
> gives code to be input, whether to the Python or Windows command prompt I am not
>
> sure, but both seem to be resistant to it. I quote the response to the code below,
It was because I thought I saw such a mixup in your earlier posts that
I suggested you start with the python tutorial :-)
> Looking at the bottom of page 16, there is more code for the inputting of, that
>
>
>
> again does not take to the Windows Command Prompt or the Python command prompt,
>
> re: import urllib2
>
> from bs4 import BeautifulSoup
You probably need the above line
And you need to preceded the other lines at the python (not shell) prompt
On the whole it may be a good idea to put aside the book and just follow the quick start http://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start
at the python prompt
>
> url = "http://www.packtpub.com/books"
>
> page = urllib2.urlopen(url)
>
> soup_packtpage = BeautifulSoup(page)
>
>
>
> returns to the Windows Command prompt:-
>
> ----------------------------------------------------------------------------------
>
> >>>import urllib2
>
> Traceback (most recent call last):
>
> File "<stdin>", line1, in <module>
>
> ImportError: No module named 'urllib2'
>
> >>>
>
>
>
> ----------------------------------------------------------------------------------
>
> returns to the Python command prompt :-
>
> ----------------------------------------------------------------------------------
>
> >>> import urllib2
>
> >>> from bs4 import BeautifulSoup
>
> >>> url = "http://www.packtpub.com/books"
>
> >>> page = urllib2.urlopen(url)
>
> Traceback (most recent call last):
>
> File "C\Python27\lib\urllib2.py",line 127, in urlopen
>
> return_opener.open(url, data, timeout)
>
> File "C:\Python27\lib\urllib2.py",line 410, in open
>
> response = meth(req, response)
>
> File "C:\Pyton27\lib\urllib2.py", oine 523, in http_response
>
> 'http', request, response, code, msg, hdrs)
>
> File"C:\Python27\lib\urllib2.py", line 448, in error
>
> return self._call_chain(*args)
>
> File "C:/Python27/lib/urllib2.py",line 382, in _call_chain
>
> result = func(*args)
>
> File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
>
> raise HTTPError(req.get_full_url(), code, masg, hdrs, fp)
>
> urllib2.HTTPError: HTTP Error 403: Forbidden
>
> ---------------------------------------------------------------------------------
>
> Anway I hope you can tell me what is amiss, there is no point in my proceeding
>
>
>
> with the book (about 111 pages all told) until I find out why it won't take.
>
> I realise I have been told to learn python in order to make things less painful,
>
>
>
> but I don't see why code written in the book does not take.
>
> Thank you for reading.
>
>
>
>
>
>
>
>
>
>
>
> I thought I might as well include, so's you might be able to see where things are
>
>
>
> going astray. The Windows command prompt :-
More information about the Python-list
mailing list