ElementTreeを使用して<paste_key>
に値を抽出しようとしていますが、次のエラーが表示されます。誰かが私が間違っていることを私に見せてくれるの?python要素ツリーの抽出値が機能しない
from pastebin import PastebinAPI
from xml.etree import cElementTree as ET
import time
x = self.apiobject.pastes_by_user(api_dev_key=self.DEVKEY, api_user_key=self.userkey)
print x
x = ET.fromstring(x)
for key in list(x):
self.pastekeys.append(key.find('paste_key').text)
print self.pastekeys
エラー出力:
問題は、XML構造である場合にはBeautifulSoupを試し、その後x
<paste>
<paste_key>afafafaf</paste_key>
<paste_date>1508796842</paste_date>
<paste_title>1508796842</paste_title>
<paste_size>36096</paste_size>
<paste_expire_date>0</paste_expire_date>
<paste_private>2</paste_private>
<paste_format_long>None</paste_format_long>
<paste_format_short>text</paste_format_short>
<paste_url>https://pastebin.com/afafafaf</paste_url>
<paste_hits>0</paste_hits>
</paste>
<paste>
<paste_key>asdfasdf</paste_key>
<paste_date>1508796842</paste_date>
<paste_title>1508796842</paste_title>
<paste_size>36096</paste_size>
<paste_expire_date>0</paste_expire_date>
<paste_private>2</paste_private>
<paste_format_long>None</paste_format_long>
<paste_format_short>text</paste_format_short>
<paste_url>https://pastebin.com/asdfasdf</paste_url>
<paste_hits>0</paste_hits>
</paste>
...
をそのを指摘するために、問題はあなたの ''要素は、単一のルート要素内に含まれていないことかもしれません。 –