BeautifulSoup を使用して特定の属性の子要素を検索したいと思います。以下のメソッドを使用して確認できることから、各子は文字列です (child['value'] は「文字列インデックスは整数でなければなりません」と表示されます)。属性に基づく選択、またはそれらの属性の返還、これは私がする必要があることです。
def get_value(container):
html_file = open(html_path)
html = html_file.read()
soup = BeautifulSoup(html)
values = {}
container = soup.find(attrs={"name" : container})
if (container.contents != []):
for child in container.children:
value = unicode(child['value']) # i would like to be able to search throught these children based on their attributes, and return one or more of their values
return value
おそらく、さらにchild_soup Beautifulsoup(child)
find コマンドを使用してこれを回避できますが、これは本当にひどいようです。誰かがより良い解決策を得ましたか?