当前位置: 首页 > news >正文

网上给别人做设计的网站/网站建设报价单

网上给别人做设计的网站,网站建设报价单,房产最新政策,网络安全形势下怎么建设学校网站我正在尝试使用NLTK库训练数据。 我遵循一个逐步的过程。 我做了第一步,但是在做第二步时,出现以下错误:TypeError: a bytes-like object is required, not list我已尽力纠正了它,但又遇到了同样的错误。这是我的代码:…

我正在尝试使用NLTK库训练数据。 我遵循一个逐步的过程。 我做了第一步,但是在做第二步时,出现以下错误:

TypeError: a bytes-like object is required, not 'list'

我已尽力纠正了它,但又遇到了同样的错误。

这是我的代码:

from bs4 import BeautifulSoup

import urllib.request

response = urllib.request.urlopen('http://php.net/')

html = response.read()

soup = BeautifulSoup(html,"html5lib")

text = soup.get_text(strip=True)

print (text)

这是我的错误

C:\python\lib\site-packages\bs4\__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 8 of the file E:/secure secure/chatbot-master/nltk.py. To get rid of this warning, change code that looks like this:

BeautifulSoup(YOUR_MARKUP})

to this:

BeautifulSoup(YOUR_MARKUP,"html5lib")

markup_type=markup_type))

Traceback (most recent call last):

File"E:/secure secure/chatbot-master/nltk.py", line 8, in

soup = BeautifulSoup(html)

File"C:\python\lib\site-packages\bs4\__init__.py", line 228, in __init__

self._feed()

File"C:\python\lib\site-packages\bs4\__init__.py", line 289, in _feed

self.builder.feed(self.markup)

File"C:\python\lib\site-packages\bs4\builder\_html5lib.py", line 72, in feed

doc = parser.parse(markup, **extra_kwargs)

File"C:\python\lib\site-packages\html5lib\html5parser.py", line 236, in parse

parseMeta=parseMeta, useChardet=useChardet)

File"C:\python\lib\site-packages\html5lib\html5parser.py", line 89, in _parse

parser=self, **kwargs)

File"C:\python\lib\site-packages\html5lib\tokenizer.py", line 40, in __init__

self.stream = HTMLInputStream(stream, encoding, parseMeta, useChardet)

File"C:\python\lib\site-packages\html5lib\inputstream.py", line 148, in HTMLInputStream

return HTMLBinaryInputStream(source, encoding, parseMeta, chardet)

File"C:\python\lib\site-packages\html5lib\inputstream.py", line 416, in __init__

self.rawStream = self.openStream(source)

File"C:\python\lib\site-packages\html5lib\inputstream.py", line 453, in openStream

stream = BytesIO(source)

TypeError: a bytes-like object is required, not 'list'

您是否看过这篇文章:stackoverflow.com/questions/16206380/? 您可以尝试get_text:crummy.com/software/BeautifulSoup/bs4/doc/#get-text

我尝试运行您的脚本,它返回文本就好了吗? 您可以发布详细的错误消息吗?

在运行即时消息时出现这样的错误

TypeError:需要一个类似字节的对象,而不是列表

脚本运行正常,请编辑问题并添加错误消息。

我试图粘贴完整的错误,但它没有发布@ sid2491

您可以通过实现一个简单的标签剥离器来实现。

def strip_tags(html, invalid_tags):

soup = BeautifulSoup(html)

for tag in soup.findAll(True):

if tag.name in invalid_tags:

s =""

for c in tag.contents:

if not isinstance(c, NavigableString):

c = strip_tags(unicode(c), invalid_tags)

s += unicode(c)

tag.replaceWith(s)

return soup

html ="

Love, Hate, and Happinessy

invalid_tags = ['b', 'i', 'u']

print strip_tags(html, invalid_tags)

结果是:

Love, Hate, and Happiness

您的代码按原样工作。

UserWarning: No parser was explicitly specified是您的语句为soup = BeautifulSoup(html)的时间。

TypeError: a bytes-like object is required, not 'list'错误可能是由于依赖关系问题引起的。

bs4文档说如果不指定解析器(如BeautifulSoup(markup)),它将使用系统上安装的最佳HTML解析器:

If you don’t specify anything, you’ll get the best HTML parser that’s installed. Beautiful Soup ranks lxml’s parser as being the best, then html5lib’s, then Python’s built-in parser.

在我的系统上,使用BeautifulSoup(html,"html.parser")效果很好,速度不错,没有任何警告。 html.parser带有Python的标准库。

该文档还总结了每个解析器库的优缺点:

尝试BeautifulSoup(html,"html.parser")。 它应该工作。

如果需要速度,可以尝试BeautifulSoup(html,"lxml")。 如果您没有lxml的HTML解析器,则在Windows上,可能需要使用pip install lxml进行安装。

对于寻找在python 3中有效的答案的任何人

invalidTags = ['br','b','font']

def stripTags(html, invalid_tags):

soup = BeautifulSoup(html,"lxml")

for tag in soup.findAll(True):

if tag.name in invalid_tags:

s ="::"

for c in tag.contents:

if not isinstance(c, NavigableString):

c = stripTags(str(c), invalid_tags)

s += str(c)

tag.replaceWith(s)

return soup

http://www.lbrq.cn/news/1579213.html

相关文章:

  • 白城市住房建设局网站/营销策划师
  • 程序员做交友网站/商城小程序开发哪家好
  • 河南省汝州市文明建设网站/南宁seo排名外包
  • 松江泖港网站建设/百度关键词代做排名
  • 应用制作下载/怀来网站seo
  • 安徽省建设行业质量与安全协会网站/怎么开一个网站平台
  • 网站服务器多少钱一月/网络营销的优缺点
  • 企业网站设计经典案例/seo实战培训王乃用
  • 教育类网站如何做/合肥seo网站管理
  • 免费b2b网站大全免费黄页/seo课程总结
  • 专业的网站建设公/长沙县网络营销咨询
  • 一站式网站建设与运营/30个免费货源网站
  • 如何建微信商城网站/广州婚恋网站排名
  • 建站域名/营销型网站分析
  • 网站的系统建设方式/网站关键词优化培训
  • 网站淘宝客怎么做的/网上售卖平台有哪些
  • wordpress媒体库删除/网络优化是干什么的
  • 网站 做百度推广有没有效果怎么样/品牌宣传方式
  • 深圳做律师网站公司/深圳网站优化平台
  • 拼多多卖网站建设/googleplay官方下载
  • 国内漂亮网站欣赏/营销软文范例大全300
  • 西安网站注册/企业网站seo排名
  • wordpress新打开空白页/举例说明seo
  • 营销型网站建设论文/软考培训机构哪家好一点
  • 如何做自己网站/微博推广效果怎么样
  • 承接网站建设 优帮云/电商营销推广方案
  • 广告公司做网站的效果怎么样/网络营销优化培训
  • 手机网站轮播图/鹤壁seo公司
  • 威县做网站哪里便宜/郑州网站推广公司排名
  • 南山做网站方案/seo搜索优化是什么
  • Myqsl建立库表练习
  • 完整多端口 Nginx Docker部署 + GitLab Runner注册及标签使用指南
  • 编程技能:递归
  • OrbStack 入门教程:macOS 上的轻量级容器与虚拟机管理工具
  • 导入CSV文件到MySQL
  • (Arxiv-2025)Phantom:通过跨模态对齐实现主体一致性视频生成