Maison > Questions et réponses > le corps du texte
天蓬老师2017-04-18 10:05:44
data = {
"title": "魅族 32G 魅蓝note5"
}
import json
print(json.dumps(data, ensure_ascii=False, encoding="utf-8"))
高洛峰2017-04-18 10:05:44
chcp 65001
Tapez-le simplement directement dans le terminal.
ლ(╹◡╹ლ), euh, peut-être, hein ?
ringa_lee2017-04-18 10:05:44
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>> import requests
>>> data = requests.get('http://zhuanzhuan.58.com/detail/807158202296418308z.shtml').content
>>> soup = BeautifulSoup(data,'lxml')
>>> title = soup.select('.box_left_top h1')[0].text.encode('utf-8')
>>> print type(title)
<type 'str'>
>>> print title
魅族 32G 魅蓝note5
>>> test_data = {'title':title}
>>> print test_data
{'title': '\xe9\xad\x85\xe6\x97\x8f 32G \xe9\xad\x85\xe8\x93\x9dnote5'}
>>> print repr(test_data).decode("unicode-escape")
{'title': u'魅族 32G 魅蓝note5'}