鱼C论坛

 找回密码
 立即注册
查看: 1658|回复: 3

[已解决]求助,按照零基础入门学习PYTHON,小甲鱼的书写的报错

[复制链接]
发表于 2017-8-18 17:23:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
先不说废话,上代码,书本173页



  1. import urllib.request
  2. import urllib.parse
  3. import re

  4. from bs4 import BeautifulSoup

  5. def demo():
  6.     keyword = input("enter a keyword:")
  7.     keyword = urllib.parse.urlencode({"word":keyword})
  8.     response =urllib.request.urlopen("http://baike.baidu.com/search/word?%s"%keyword)
  9.     html = response.read()
  10.     soup = BeautifulSoup(html,"html.parse")
  11.    
  12.     for each in soup.find_all(href = re.compile("view")):
  13.         content = "".join([each.text])
  14.         url2 = "".join(["http://baike.baidu.com",each["href"]])
  15.         response2 = urllib.request.urlopen(url2)
  16.         html2 = response2.read()
  17.         soup2 = BeautifulSoup(html2,"html.parse")        
  18.         if soup.h2:
  19.             content = "".join([content,soup2.h2.text])
  20.         content = "".join([content,"->",url2])
  21.         print(content)
  22.    
  23. if __name__=="__main__":
  24.     demo()
复制代码


以下是报错:


  1. enter a keyword:111
  2. Traceback (most recent call last):
  3.   File "E:\systemtemp\eclipsework\PydevDemo\src\xiaojiayu\BeautifuSoup4Demo.py", line 68, in <module>
  4.     demo()
  5.   File "E:\systemtemp\eclipsework\PydevDemo\src\xiaojiayu\BeautifuSoup4Demo.py", line 54, in demo
  6.     soup = BeautifulSoup(html,"html.parse")
  7.   File "D:\application\Python\Python35\lib\site-packages\bs4\__init__.py", line 165, in __init__
  8.     % ",".join(features))
  9. bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html.parse. Do you need to install a parser library?
复制代码




新手,求教如何解决?
最佳答案
2017-8-18 22:05:34
因为你抄错了……

  1. soup2 = BeautifulSoup(html2,"html.parse")
复制代码

应该是

  1. soup2 = BeautifulSoup(html2,"html.parser")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-8-18 22:05:34 | 显示全部楼层    本楼为最佳答案   
因为你抄错了……

  1. soup2 = BeautifulSoup(html2,"html.parse")
复制代码

应该是

  1. soup2 = BeautifulSoup(html2,"html.parser")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-19 16:37:59 | 显示全部楼层
小甲鱼 发表于 2017-8-18 22:05
因为你抄错了……

哈哈哈
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-19 17:55:18 | 显示全部楼层
害得我还跑到ubuntu下重新配置环境,搞了两天。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-28 16:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表