鱼C论坛

 找回密码
 立即注册
查看: 1753|回复: 2

为什么我的代码既不报错,也输出结果,求解各位大佬

[复制链接]
发表于 2017-12-28 16:17:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import requests
from multiprocessing import Pool
from requests.exceptions import RequestException
import re
import json

def get_one_page(url):
    try:
        response = requests.get(url)
        if response.status_code == 200 :
            return response.text
        return None
    except RequestException:
        return None

def parse_one_page(html):
    pattern = re.compile('<dd>.*?board-index.*?>(\d+)</i>.*?board-img.*?src"(.*?)".*?>name"><a.*?>(.*?)</a>.*?star">(.*?)</p>.*?releasetime">(.*?)</p>.*?integer">(.*?)</i>.*?fraction">(.*?)</i></p>', re.S)
    items = re.findall(pattern, html)
    parse_one_page(html)

    for item in items:
        yield {
            'index' : item[0],
            'img': item[1],
            'title': item[2],
            'actor': item[3].strip()[3:0],
            'time': item[4].strip()[5:0],
            'score': item[5] + item[6],
        }

def write_to_file(content):
    with open('result.txt','a',encoding='utf-8') as f:
        f.write(json.dumps(content, ensure_ascii=False) + '\n')
        f.close()

def main(offset):
    url = 'http://maoyan.com/board/4?offset=' + str(offset)
    html = get_one_page(url)
    for item in parse_one_page(html):
        print(item)


if __name__ == '__main':
        pool = Pool()
        pool.map(main, [i*10 for i in range(10) ])
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-12-31 02:33:56 | 显示全部楼层
打print调试或者debug
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-2 20:12:40 | 显示全部楼层
if __name__ == '__main':
        pool = Pool()
        pool.map(main, [i*10 for i in range(10) ])

main后面还要双下划线 if __name__ =='__main__'
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-26 19:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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