类型错误:__init__()缺少两个必需的位置参数:'selfClosingTags'和'isHTML'

2024-09-30 12:25:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个学习测试程序时出错了。在

代码如下:

from bs4 import BeautifulSoup

newurl = 'http://susumr.cc/'
soup = BeautifulSoup(newurl,'lxml')
print(soup.text)

我有个错误:

^{pr2}$

第三方库我也安装了,我不知道这是怎么回事,而且困惑了好几天


Tags: 代码textfromimporthttp错误lxml测试程序
1条回答
网友
1楼 · 发布于 2024-09-30 12:25:25

您需要将html字符串传递给BeautifulSoup构造函数,而不是url。在

import urllib

from bs4 import BeautifulSoup

newurl = 'http://susumr.cc/'
content = urllib.urlopen(newurl).read()  # Retrive url content
soup = BeautifulSoup(content, 'lxml')  # pass the content to `BeautifulSoup` constructor
print(soup.text)

相关问题 更多 >

    热门问题