2024-09-30 12:25:25 发布
网友
我在做一个学习测试程序时出错了。在
代码如下:
from bs4 import BeautifulSoup newurl = 'http://susumr.cc/' soup = BeautifulSoup(newurl,'lxml') print(soup.text)
我有个错误:
第三方库我也安装了,我不知道这是怎么回事,而且困惑了好几天
您需要将html字符串传递给BeautifulSoup构造函数,而不是url。在
BeautifulSoup
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)
您需要将html字符串传递给
BeautifulSoup
构造函数,而不是url。在相关问题 更多 >
编程相关推荐