BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

BeautifulSoup很赞的东西

最近出现一个问题:Python 3.3

soup=BeautifulSoup(urllib.request.urlopen(url_path),"html.parser")

soup.findAll("a",{"href":re.compile(‘^http|^/‘)})

出现warning:

Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

在极少数情况下(通常当UTF-8文档包含以完全不同的编码编写的文本时),获取Unicode的唯一方法是使用特殊的Unicode字符“REPLACEMENT CHARACTER”(U + FFFD)替换某些字符。 如果是Unicode,Dammit需要这样做,它将在UnicodeDammit或BeautifulSoup对象上将.contains_replacement_characters属性设置为True。 这让您知道Unicode表示不是原始的精确表示 - 一些数据丢失。 如果文档包含 ,但是.contains_replacement_characters为False,那么您将知道 原来是存在的,并且不代表缺少的数据。

解决:soup=BeautifulSoup(urllib.request.urlopen(url_path),""html.parser",from_encoding="iso-8859-1")

时间: 2024-08-26 05:23:44

BeautifulSoup Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.的相关文章

BeautifulSoup请求的html内容之后得到一个空的对象

今天写爬虫的时候,遇到了一个奇怪的问题,请求得到html内容之后,将对象使用Beautiful处理之后,竟然得到了空的内容. import requests from bs4 import BeautifulSoup headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36','Upg

字符串和字符(Strings and Characters)

字符串和字符(Strings and Characters) 本页包含内容: 字符串字面量 初始化空字符串 字符串可变性 字符串是值类型 使用字符 计算字符数量 连接字符串和字符 字符串插值 比较字符串 字符串大小写 Unicode String是例如“hello, world”,“海贼王” 这样的有序的Character(字符)类型的值的集合,通过String类型来表示. Swift 的String和Character类型提供了一个快速的,兼容 Unicode 的方式来处理代码中的文本信息.

*Common characters

Write a program that gives count of common characters presented in an array of strings..(or array of character arrays) For eg.. for the following input strings.. aghkafgklt dfghako qwemnaarkf The output should be 3. because the characters a, f and k

python学习之函数

1.函数名可以被赋值 比如: def aaa(): pass b = aaa//将函数名字赋值给b b()//跟aaa()效果一样 2.return 2.1.如果函数不写return的话,会默认返回None 2.2.return后,函数下面的语句不会被执行,中断函数操作 2.3.return个什么东西都行,哪怕是个列表..... 3.pycharm使用断点调试的话,需要用debug模式(向右小箭头的小虫子) 4.参数: 默认参数必须写在后边 def aaa(a1, a2 = 1): pass//

python3.4 build in functions from 官方文档 翻译中

2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.     Built-in Funct

String源码

/* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.lang; import java.io.ObjectStreamClass;import java.io.ObjectStreamField;import java.

bash重谈:Quoting

3.1.2 Quoting------------- * Menu: * Escape Character:: How to remove the special meaning from a single character.* Single Quotes:: How to inhibit all interpretation of a sequence of characters.* Double Quotes:: How to suppress most of the interpreta

java.lang.String类

复制下来的java.lang.String源码.在此基础上添加自己的注释,偷懒了,用来加深印象吧.英语不好,没有翻译,不理解的方法直接百度的.然后按照自己的理解描述. /* * @(#)String.java 1.205 09/02/26 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */

Python中文乱码

1,注意:请使用智慧型浏览器 "CHROME" 配合理解和运作本文中提到的程序. 2,提示:谷歌的CHROME浏览器是迄今为止最智慧的浏览器,没有之一,只有第一. 3,谷歌的CHROME浏览器最特殊的一点是:"根据字符集使用不同的后台智能解码程序". 4,本文内容请见红字部分: 使用办法为: 在文件中开头加入代码如下: #!/usr/bin/python  或 者  #!user/bin/env python # -*- coding: utf-8 -*-# -*-