Home > Q&A > body text
打印出的中文内容全是乱码但是print('中文')可以打印出中文
PHP中文网2017-04-17 17:39:53
See this previous posthttps://segmentfault.com/q/1010000004887283/a-1020000004887790
Need to declare the encoding format of the file
1
2
3
4
5
6
7
8
9
10
<code># -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import requests
url = "http://news.baidu.com"
url =
"http://news.baidu.com"
data = requests.get(url)
s = BeautifulSoup(data.text.encode(data.encoding), "lxml")
s = BeautifulSoup(data.text.encode(data.encoding),
"lxml"
)
title = s.select("#pane-news > p > ul > li.hdline0")
title = s.select(
"#pane-news > p > ul > li.hdline0"
print(title)</code>
print
(title)</code>
天蓬老师2017-04-17 17:39:53
Thank you very much! ! !