How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

Simon Evans musicalhacksaw at yahoo.co.uk
Thu May 15 07:25:42 EDT 2014



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, 

the code input being :- 

helloworld = "<p>Hello World</p>"
soup_string = BeautifulSoup(helloworld)

to Windows Command prompt this gives :- 
----------------------------------------------------------------------------------
SyntaxError: invalid syntax
>>> helloworld = "<p>HelloWorld</p>"
>>> soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'BeautifulSoup' is not defined
----------------------------------------------------------------------------------
I have been told by one of the programmers, that I ought be inputting this to the 

Python command prompt (the book doesn't spacify), but that doesn't take either 

re:-
----------------------------------------------------------------------------------
>>>helloworld = <p>HelloWorld</p>"
>>>soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'BeautifulSoup' is not defined
>>>
----------------------------------------------------------------------------------
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
     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