我想读取 count 中存在的整数tags。
这是我写的代码:
import xml.etree.ElementTree as ET
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = 'http://py4e-data.dr-chuck.net/comments_42.xml'
content1 = urllib.request.urlopen(url, context = ctx).read()
soup = BeautifulSoup(content1, 'html.parser')
tree = ET.fromstring(soup)
tags = tree.findall('count')
print(tags)
它抛出一个错误:
Traceback (most recent call last):
File "C:\Users\Name\Desktop\Py4e\Me\Assi_15_01.py", line 15, in <module>
tree = ET.fromstring(soup)
File "C:\Users\Name\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 1320, in XML
parser.feed(text)
TypeError: a bytes-like object is required, not 'BeautifulSoup'
我能做些什么?
更多信息:http://py4e-data.dr-chuck.net/comments_42.xml
SMILET
白衣非少年
相关分类