找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2127|回复: 1

[求助] Pycharm 使用print语句无法显示output

1

主题

1

帖子

1

积分

贫民

积分
1
psong_24 发表于 2018-12-4 13:24:11 | 显示全部楼层 |阅读模式
我在使用pycharm的时候只是使用简单的代码print
e.g.
def main():    print ('sdf')    if __name__ == '__main__':        main()run tool的结果
/Library/Frameworks/Python.framework/Versi**/2.7/bin/python /Users/jiansong/PycharmProjects/untitled1/sdfsd.py

Process finished with exit code 0

c**ole也不是显示结果。
网上说需要在execution那里设置 emulate terminal in output c**ole,但是依旧没有结果。

想问一下大家是什么问题?


回复

使用道具 举报

3

主题

34

帖子

34

积分

贫民

积分
34
彭国禹 发表于 2018-12-5 10:53:44 | 显示全部楼层
请用代码模式编辑你的代码,重新发帖吧,你这样代码看不到缩进。
代码模式示范:
  1. import time
  2. import re
  3. import json
  4. import requests


  5. def one_page(url):
  6.     header = {
  7.         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'
  8.     }
  9.     resp**e = requests.get(url, headers=header)
  10.     if resp**e.status_code == 200:
  11.         return resp**e.text
  12.     else:
  13.         print('Fetch nothing. URL: {}'.format(url))
  14.         return None


  15. def to_file(file, contents):
  16.     pattern = re.compile('<dd>.*?board-index board-index.*?>(\d)</i>.*?<img data-src.*?(https.*?)".*?'
  17.                          '<p class="name">.*?title="(.*?)".*?<p class="star">.*?主演:(.*?)</p>.*?class="releasetime">.*?上映时间:(.*?)</p>'
  18.                          '.*?<i class="integer">(.*?)</i>.*?</dd>', re.S)
  19.     items = pattern.findall(contents)
  20.     for each in items:
  21.         with open(file, 'a+') as fh:
  22.             content = {'排名': each[0],
  23.                        '海报图片': each[1],
  24.                        '名称': each[2].strip(),
  25.                        '主演': each[3].strip(),
  26.                        '上映时间': each[4].strip(),
  27.                        '评分': each[-1].strip()}
  28.             json.dump(content, fh, ensure_ascii=False)


  29. def main():
  30.     for i in range(10):
  31.         url = 'https://maoyan.com/board/4?offset=' + str(10*i)
  32.         html = one_page(url)
  33.         to_file('maoyan_top_100.txt', html)
  34.         time.sleep(2)
  35.         print('Fetching data...')
  36.     print('Done!')

  37. if __name__ == '__main__':
  38.     main()
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表