BS4:" soup.title.string"在IDLE但终端不工作 [英] bs4: "soup.title.string" doesn't work on IDLE but Terminal

查看:438
本文介绍了BS4:" soup.title.string"在IDLE但终端不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的Mac OS X 10.9
Python 2.7版IDLE
BeautifulSoup 4安装(成功)

Mac OS X 10.9 Python 2.7 IDLE BeautifulSoup 4 installed (successfully)

我跟着 BS4文档并练习一些功能<强>在IDLE 。下面code ++工程,并能打印出标题和放大器; title.name。

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 = """
<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 a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""

soup = BeautifulSoup(html)


print soup.title
print soup.title.name

打印结果:

<title>The Dormouse's story</title>
title

但正如我提出和试图打印soup.title.string下一行:

But as I moved on and tried to print soup.title.string in the next line:

print soup.title.string

,它返回:

Traceback (most recent 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: an integer is required

,然后我试图运行在终端在同一code:

AND THEN, I tried to run the same code on Terminal:

Python的[文件名]的.py

Python [filename].py

它的工作!

<title>The Dormouse's story</title>
title
The Dormouse's story

有人能解释为什么code没有空闲,但终端工作?谢谢!

Can someone explained why the code didn't work on IDLE but Terminal? Thank you!

推荐答案

这是一个已知的bug汇报了Python的问题跟踪器的问题#23583:IDLE:打印UNI code子坏了(再次)

This was a known bug, reported on the Python issue tracker as issue #23583: IDLE: printing unicode subclasses broken (again).

这是几个月前固定的,2.7.10版本这应该不再发生如此开始。尝试更新你的Python!

This was fixed a few months ago, so beginning with version 2.7.10 this should no longer happen. Try updating your Python!

这篇关于BS4:&QUOT; soup.title.string&QUOT;在IDLE但终端不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆