link 发表于 2018-8-16 12:44:17

python用print输出中文字符

  判断了字符集之后,如要显示中文,需要用print。示例如下:
  import urllib2
  import re
  page = 1
  url = 'http://www.qiushibaike.com/hot/page/' + str(page)
  user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
  headers = { 'User-Agent' : user_agent }
  out_file = open ("qiushibaike.txt", "w")
  request = urllib2.Request(url,headers = headers)
  response = urllib2.urlopen(request)
  buf=response.read()
  out_file.write(buf)
  out_file.close()
  list_jpg=re.findall(r'http://.+\.jpg', buf)
  list_joketxt=re.findall(r'.+', buf)
  print buf #输出网页源文件,格式正确,中文显示正常
  # list_jpg=re.findall(r'
页: [1]
查看完整版本: python用print输出中文字符