- 如何将汉字转换为拼音
>>> from xpinyin import Pinyin
>>> p = Pinyin()
>>> # default splitter is `-`
>>> p.get_pinyin(u"上海")
'shang-hai'
>>> # show tone marks
>>> p.get_pinyin(u"上海", show_tone_marks=True)
'shàng-hǎi'
>>> # remove splitter
>>> p.get_pinyin(u"上海", '')
'shanghai'
>>> # set splitter as whitespace
>>> p.get_pinyin(u"上海", ' ')
'shang hai'
>>> p.get_initial(u"上")
'S'
>>> p.get_initials(u"上海")
'S-H'
>>> p.get_initials(u"上海", u'')
'SH'
>>> p.get_initials(u"上海", u' ')
'S H'
- 获取城市的油价
import urllib.request
import re
url = r'http://youjia.chemcp.com/shanndong/jinanshi.html'
res = urllib.request.urlopen(url)
html = res.read().decode('gb2312')
par = '( )(.*?)(<br />)'
web = re.search(par,html).group(2)
web = web.split(' ',1)[0]
cml = web.replace('<font color="red">',':')
cml = cml.replace('</font>','')
cml = cml.replace(',','\n')
cml = cml.replace(':','\n',1)
cml = cml.replace(',','\n')
print (cml)
参考链接:
http://www.javashuo.com/article/p-tdoeeudk-ct.html