Mac OS X 10.9 Python 2.7 IDLE BeautifulSoup 4 installed (successfully)
I followed BS4 documentation and was practicing some of the functions on IDLE. The following code works and was able to print out title & title.name.
from bs4 import BeautifulSoup html = """ The Dormouse's story The Dormouse's story
Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well.
...
""" soup = BeautifulSoup(html) print soup.title print soup.title.name
Print result:
The Dormouse's story title
But as I moved on and tried to print soup.title.string in the next line:
print soup.title.string
It returned:
Traceback (most recent call last): File "/Users/yumiyang/Documents/python-folder/bsoup_test.py", line 24, in print soup.title.string File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib/PyShell.py", line 1344, in write s = unicode.__getslice__(s, None, None) TypeError: an integer is required
AND THEN, I tried to run the same code on Terminal:
Python [filename].py
It worked!
The Dormouse's story title The Dormouse's story
Can someone explained why the code didn't work on IDLE but Terminal? Thank you!