Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Beautifulsoup特殊字符分析错误_Python_Beautifulsoup - Fatal编程技术网

Python Beautifulsoup特殊字符分析错误

Python Beautifulsoup特殊字符分析错误,python,beautifulsoup,Python,Beautifulsoup,我正在使用BeautifulSoup和urllib2从互联网上收集内容。 这是我正在使用的代码 from bs4 import BeautifulSoup import urllib2 html = urllib2.urlopen('http://plrplr.com/33717/mp3-player-guide/').read() soup = BeautifulSoup(html, "lxml") contents = soup.find('div', {'class': 'entry-c

我正在使用BeautifulSoup和urllib2从互联网上收集内容。 这是我正在使用的代码

from bs4 import BeautifulSoup
import urllib2

html = urllib2.urlopen('http://plrplr.com/33717/mp3-player-guide/').read()
soup = BeautifulSoup(html, "lxml")
contents = soup.find('div', {'class': 'entry-content'})
print contents
但是我得到了这样的结果

<div class="entry-content">
<p>MP3 player, also well known as digital audio player has become a staple of our gadget life. There are many brands of MP3 players on the market today. So, which MP3 player are the most suitable for you? That’s where this MP3 player guide comes in. <br/>
Basically, there are 3 types of MP3 player based on capacity: – <br/>
1. Hard drive MP3 player <br/>
– highest capacity <br/>
– largest in size <br/>
– heavy <br/>
– often labeled as an “Jukebox MP3 player� <br/>
– has moving parts <br/>
– example: Apple iPod video, Sony Network Walkman NW-HD5 <br/>
    <div class="entry-content">
        <p>MP3 player, also well known as digital audio player has become a staple of our gadget life. There are many brands of MP3 players on the market today. So, which MP3 player are the most suitable for you? That&#8217;s where this MP3 player guide comes in. </br><br />
Basically, there are 3 types of MP3 player based on capacity: &#8211; </br><br />
1. Hard drive MP3 player </br><br />
&#8211; highest capacity </br><br />
&#8211; largest in size </br><br />
&#8211; heavy </br><br />
&#8211; often labeled as an &#8220;Jukebox MP3 player&#8221; </br><br />
&#8211; has moving parts </br><br />
&#8211; example: Apple iPod video, Sony Network Walkman NW-HD5 </br><br />

MP3播放器,也被称为数字音频播放器,已经成为我们生活中的必需品。今天市场上有许多品牌的MP3播放器。那么,哪个MP3播放器最适合你?那是€™这就是MP3播放器指南的用武之地
基本上,根据容量有3种类型的MP3播放器:1–2“
1.硬盘MP3播放器
–最高容量
“最大的尺寸
–欧元“重
通常被标记为“自动点唱机MP3播放器”€?
–欧元“有活动部件
–示例:苹果iPod视频,索尼网络随身听NW-HD5
处理特殊字符时出现问题

我怎样才能得到像这样精确的源代码

<div class="entry-content">
<p>MP3 player, also well known as digital audio player has become a staple of our gadget life. There are many brands of MP3 players on the market today. So, which MP3 player are the most suitable for you? That’s where this MP3 player guide comes in. <br/>
Basically, there are 3 types of MP3 player based on capacity: – <br/>
1. Hard drive MP3 player <br/>
– highest capacity <br/>
– largest in size <br/>
– heavy <br/>
– often labeled as an “Jukebox MP3 player� <br/>
– has moving parts <br/>
– example: Apple iPod video, Sony Network Walkman NW-HD5 <br/>
    <div class="entry-content">
        <p>MP3 player, also well known as digital audio player has become a staple of our gadget life. There are many brands of MP3 players on the market today. So, which MP3 player are the most suitable for you? That&#8217;s where this MP3 player guide comes in. </br><br />
Basically, there are 3 types of MP3 player based on capacity: &#8211; </br><br />
1. Hard drive MP3 player </br><br />
&#8211; highest capacity </br><br />
&#8211; largest in size </br><br />
&#8211; heavy </br><br />
&#8211; often labeled as an &#8220;Jukebox MP3 player&#8221; </br><br />
&#8211; has moving parts </br><br />
&#8211; example: Apple iPod video, Sony Network Walkman NW-HD5 </br><br />

MP3播放器,也被称为数字音频播放器,已经成为我们生活中的必需品。现在市场上有很多品牌的MP3播放器。那么,哪个MP3播放器最适合您?这就是本MP3播放器指南的用武之地。

基本上,根据容量,MP3播放器有三种类型:–;

1.硬盘MP3播放器

–;最高容量

–;尺寸最大

–;重型 –;通常标记为自动存储塔MP3播放器 –;有活动部件

–;示例:苹果iPod视频,索尼网络随身听NW-HD5

我正在使用Eclipse和pydev在Windows 8计算机上运行此代码。

您可能要查找的是
内容。prettify(formatter=“html”)
以显示实体代码而不是非ascii字母


我无法在我的机器上测试这一点,但以下是我使用的文档:

要么网站提供了无效的字符编码,要么您应该将其显式设置为UTF-8。问题似乎与beautifulsoup无关,但这一行:
html=urllib2.urlopen('http://plrplr.com/33717/mp3-player-guide/)。读()
也许这对你有帮助:我刚刚运行了你的代码。它和你的代码一样对我很好。虽然我会将
'div',{'class':'entry content'}
更新为
'div',class_quo=“entry content”
。您使用的是哪种终端和字符集?以及python的哪种版本?我认为这可能是环境问题。也许这可能与此相关: