84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
业精于勤,荒于嬉;行成于思,毁于随。
# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup url = 'http://nj.lianjia.com/xiaoqu/' html = requests.get(url) soup = BeautifulSoup(html.text.encode(html.encoding), 'lxml', from_encoding='utf-8') title = soup.title.get_text() print(title)
1) Add # -- coding: utf-8 --statement2) Correctly handle the encoding of the returned response
That’s right upstairs, in fact you can also use Latin1encoding to decode this text.
Latin1
import requests from bs4 import BeautifulSoup url = 'http://nj.lianjia.com/xiaoqu/' html = requests.get(url) soup = BeautifulSoup(html.text, 'lxml') title = soup.title.get_text() print(title.encode('latin1').decode('utf-8'))
1) Add # -- coding: utf-8 --statement
2) Correctly handle the encoding of the returned response
That’s right upstairs, in fact you can also use
Latin1
encoding to decode this text.