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