使用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)

  

相关文章:

  • 2021-12-31
  • 2021-09-28
  • 2022-12-23
  • 2022-01-21
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
猜你喜欢
  • 2022-12-23
  • 2022-01-17
  • 2021-04-28
  • 2022-12-23
  • 2021-12-03
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案