我试图做一些简单的字符串操作与超链接的href属性提取使用Beautiful Soup:简单的Python /美丽的汤类型的问题
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup('<a href="http://www.some-site.com/">Some Hyperlink</a>')
href = soup.find("a")["href"]
print href
print href[href.indexOf('/'):]
我得到的是:
Traceback (most recent call last):
File "test.py", line 5, in <module>
print href[href.indexOf('/'):]
AttributeError: 'unicode' object has no attribute 'indexOf'
我应该如何将href
转换成普通字符串?
也值得注意的Unicode字符串将具有所有相同的方法一个常规的字符串 – dbr 2009-07-20 12:17:21