用Python requests beautifulSoup 获取并显示中文信息

使用requests来打开URL地址,获取编码为utf-8

得到的标签或信息在显示时用gb18030来显示。

book_page = requests.get("https://book.douban.com/subject/26906797/", )
print(book_page.status_code)
status_code = book_page.status_code

#if status_code == 200:
#    print("The content is " + book_page.content)
    

bs_page = BeautifulSoup(book_page.content, features='lxml', from_encoding='utf8')
 
print(u"Article_info is {}")
article_info = bs_page.find_all(id='info')
for article in article_info:
    article.encode('gb18030')
    print(article.text)

  

猜你喜欢

转载自www.cnblogs.com/hanxiangmin/p/11294420.html
今日推荐