啊陈脑壳疼 2021-03-22 21:57 采纳率: 0%
浏览 97

找不到具有所请求功能的树生成器: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也行,如上面的代码

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算