尝试将站点分别转换为xml和json时,未找到/期望值的元素

dwbf0jvd  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(139)

我已经尝试解析一个网站有一段时间了,但是在尝试解析的过程中,我不断地出错。当我尝试使用xml时,我发现:
xml.etree.elementtree.parseerror:未找到元素:第1行,第1列
当我尝试使用json时,我发现:
json.decoder.jsondecodeerror:预期值:第1行第1列(字符0)
我的xml代码是:

import urllib.request, urllib.parse, urllib.error
import ssl
import xml.etree.ElementTree as PT

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

while True:

 url= input('Enter Location: ')
 print('Retrieving', url)

 uh = urllib.request.urlopen(url, context=ctx)
 data = uh.read()
 print('Retrieved', len(data), 'characters')

 tree=PT.fromstring (uh.read())

 print (tree)
 break

我的json代码是:

import urllib.request, urllib.parse, urllib.error
import ssl
import json
import requests

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

while True:

 url= input('Enter Location: ')
 print('Retrieving', url)

 r = requests.get(url, auth=('user', 'pass'))

 m=r.json()

 print (m)
 break

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题