【发布时间】:2017-09-26 17:51:24
【问题描述】:
这是我写的python代码:
from bs4 import BeautifulSoup
url="http://www.thehindu.com/sci-tech/science/iit-bombay-birds-eye-view-and-quantum-biology/article18191268.ece"
htmltext = urllib.urlopen(url).read()
soup = BeautifulSoup(htmltext,"lxml")
webpage_title = soup.find_all('h1', attrs = {"class": "title"})
print webpage_title
这是我得到的输出:
[<h1 class="title">\nIIT Bombay: Bird\u2019s eye view and quantum biology\n</h1>]
我希望输出是:
IIT Bombay: Bird’s eye view and quantum biology
我希望将此输出存储为字符串,以便我可以将其写入文件。
我不希望标题使用 unicode。
如果是这样,那么我想要一种将 unicode 转换为 ascii 字符串的方法。
【问题讨论】:
标签: python-2.7 unicode beautifulsoup