我试图创建一个将联盟打入字典的功能。但是它似乎在字典中添加了一个数组,而不仅仅是字符串。怎么会这个
html我试图勉强:
<fieldset>
<legend align="center">
<a href="/dota2/events/297-the-summit-3">The Summit 3</a>
</legend>
</fieldset>
Python get_league函数。 self.url是html所在的网址
def get_league(self):
request = requests.get(self.url)
tree = html.fromstring(request.content)
league = tree.xpath("//legend[@align='center']/a/text()")
return league
添加到词典
data['league'] = self.get_league()[0]
JSON中的输出
"league": [
"The Summit 3"
]
预期产出
"league":"The Summit 3"