Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The file's meta tag claims that the character set is <a href="http://en.wikipedia.org/wiki/GB_2312" rel="nofollow">GB2312</a>, but the data contains a character from the newer <a href="http://en.wikipedia.org/wiki/GBK" rel="nofollow">GBK</a>/<a href="http://en.wikipedia.org/wiki/GB18030" rel="nofollow">GB18030</a> and this is what's tripping BeautifulSoup up:</p> <pre> simon@lucifer:~$ python Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> data = urllib2.urlopen('http://stock.eastmoney.com/news/1408,20101022101395594.html').read() >>> data.decode("gb2312") Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 20148-20149: illegal multibyte sequence </pre> <p>At this point, UnicodeDammit bails out, tries <a href="http://chardet.feedparser.org/" rel="nofollow">chardet</a>, <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow">UTF-8</a> and finally <a href="http://en.wikipedia.org/wiki/Windows-1252" rel="nofollow">Windows-1252</a>, which always succeeds - this is what you got, by the looks of it.</p> <p>If we tell the decoder to replace unrecognised characters with a '?', we can see the character that's missing in GB2312:</p> <pre> >>> print data[20140:20160].decode("gb2312", "replace") 毒尾气二�英的排放难 </pre> <p>Using the correct encoding:</p> <pre> >>> print data[20140:20160].decode("gb18030", "replace") 毒尾气二噁英的排放难 >>> from BeautifulSoup import BeautifulSoup >>> s = BeautifulSoup(data, fromEncoding="gb18030") >>> print s.findAll("p")[2].string[:10]   信息通信技术是&amp; </pre> <p>Also:</p> <pre> >>> print s.findAll("p")[2].string   信息通信技术是&amp;ldquo;十二五&amp;rdquo;规划重点发展方向,行业具有很强的内在增长潜 力,增速远高于GDP。软件外包、服务外包、管理软件、车载导航、网上购物、网络游戏、 移动办公、移动网络游戏、网络视频等均存在很强的潜在需求,使信息技术行业继续保持较 高增长。 </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload