bs4: "soup.title.string" doesn't work on IDLE but Terminal -
mac os x 10.9 python 2.7 idle beautifulsoup 4 installed (successfully)
i followed bs4 documentation , practicing of functions on idle. next code works , able print out title & title.name.
from bs4 import beautifulsoup html = """ <html><head><title>the dormouse's story</title></head> <body> <p class="title"><b>the dormouse's story</b></p> <p class="story">once upon time there 3 little sisters; , names <a href="http://example.com/elsie" class="sister" id="link1">elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">lacie</a> , <a href="http://example.com/tillie" class="sister" id="link3">tillie</a>; , lived @ bottom of well.</p> <p class="story">...</p> """ soup = beautifulsoup(html) print soup.title print soup.title.name
print result:
<title>the dormouse's story</title> title
but moved on , tried print soup.title.string in next line:
print soup.title.string
it returned:
traceback (most recent phone call last): file "/users/yumiyang/documents/python-folder/bsoup_test.py", line 24, in <module> 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: integer required
and then, tried run same code on terminal:
python [filename].py
it worked!
<title>the dormouse's story</title> title dormouse's story
can explained why code didn't work on idle terminal? give thanks you!
this known bug, reported on python issue tracker issue #23583: idle: printing unicode subclasses broken (again).
this fixed few months ago, origin version 2.7.10 should no longer happen. seek updating python!
string terminal beautifulsoup osx-mavericks python-idle
No comments:
Post a Comment