【发布时间】:2019-04-29 05:39:36
【问题描述】:
我正在尝试根据获取请求从网页中抓取一些数据。不久前我有一个类似的问题,用户能够向我展示如何解析 XML 响应。我开始使用相同的策略,但出现“格式不正确”的错误。我已经搜索了解决方法或解决方案,但我并没有真正到达任何地方。任何帮助将不胜感激!
我的代码如下:
import requests
from xml.etree import ElementTree as ET
import json
base_url = "https://www.gmeiutility.org/actions/Search/?isPendingValidationChecked=true&isSearchAllLOUChecked=true&keyWord=5493&page=1&resultsPerPage=15&searchType=baseSearch&sortDirection=&sortFieldName="
r = requests.get(base_url)
print(r.content)
root = ET.fromstring(r.content)
data = json.loads(root.text)
for result in data['entitySearchResult']:
print(result['LEINumber'])
【问题讨论】:
-
我的错误如下所示:xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
标签: python xml web-scraping python-requests