我試圖做一些簡單的字符串操作與超鏈接的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