???(??`?�?)
2021-03-22 21:57
采纳率: 0%
浏览 79

找不到具有所请求功能的树生成器:html.parse文件. 您需要安装解析器库吗?

import urllib.request
from urllib import request
from bs4 import BeautifulSoup
from html.parser import HTMLParser
url = 'https://pic.netbian.com/'

#1.添加头部信息
def geturl(url):
    headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"}
    rep = urllib.request.Request(url,headers=headers)
    page = urllib.request.urlopen(rep,timeout=10)
    connects = page.read()
    #print(contents)#(检测能否爬取)

#2.解析出图片链接

    soup = BeautifulSoup(connects,'html.parse')
    img_url = soup.find_all('img')
    print(img_url)
geturl(url)
#运行结果
Traceback (most recent call last):
  File "G:/python/test2.py", line 19, in <module>
    geturl(url)
  File "G:/python/test2.py", line 16, in geturl
    soup = BeautifulSoup(connects,'html.parse')
  File "G:\python\lib\site-packages\bs4\__init__.py", line 243, in __init__
    raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html.parse. Do you need to install a parser library?

Process finished with exit code 1

求解?
 

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 我不喜欢这个世界 2021-03-22 22:28
    
    soup = BeautifulSoup(connects, 'html.parser')
    
    soup = BeautifulSoup(connects, 'lxml')

    是parser  不是parse

    另外 lxml也行,如上面的代码

    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题