首页 > 这里的判断怎么样才能是True呢?

这里的判断怎么样才能是True呢?

RT,网页代码如下:

        <html>
        <head>
        <title>新浪通行证</title>
        <meta http-equiv="refresh" content="0; url=&#39;http://weibo.com/p/aj/v6/mblog/mbloglist?page=1&current_page=1&domain=100808&pre_page=1&page_bar=0&pl_name=Pl_Third_App__9&id=1008089f6e6800cfae7749eb6c486619254b9c&feed_type=1&retcode=6102&#39;"/>
        <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
        </head>
        <body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000">
        <script type="text/javascript" language="javascript">
        location.replace("http://weibo.com/p/aj/v6/mblog/mbloglist?page=1&current_page=1&domain=100808&pre_page=1&page_bar=0&pl_name=Pl_Third_App__9&id=1008089f6e6800cfae7749eb6c486619254b9c&feed_type=1&retcode=6102");
        </script>
        </body>
        </html>

我想在遇到这个页面的时候调用一个函数,于是就判断一下:

if unicode( bs_html.title.string ) == u"新浪通行证":

但是总是是False。请问是为什么呢?应该如何修改?


正好昨天用bs4

a = "圆柱:由三个面组成,上下两个底面是<span class=\"xheBtnWaKong\" index=\"2\">半径相同的圆</span>,侧面是<span class=\"xheBtnWaKong\" index=\"3\">曲面</span>"
soup = BeautifulSoup(a)
content = soup.find_all('span')
for obj in content:
    print type(obj.string)
    if obj.string.encode('utf-8') == "半径相同的圆":
        print 'aaaaa'

你的source code的charset是?另外注意html页面的charset:

【热门文章】
【热门文章】