父模块''未加载,无法在新闻检索中执行相对导入

时间:2018-09-11 09:43:07

标签: python

我试图通过此脚本通过其URL检索一些新闻报道,但是运行代码后,出现了这样的错误。

我应该如何修改代码以避免该错误?

import hashlib
import json
import logging
import os
from newsplease import NewsPlease
from ..crawler import commoncrawl_crawler as commoncrawl_crawler

def __setup__():
...
def __get_pretty_filepath(path, article):
...
def on_valid_article_extracted(article):

if __name__ == '__main__':
    __setup__()
    commoncrawl_crawler.crawl_from_commoncrawl(on_valid_article_extracted,
                                               valid_hosts=my_filter_valid_hosts,
                                               start_date=my_filter_start_date,
                                               end_date=my_filter_end_date,
                                               strict_date=my_filter_strict_date,
                                               reuse_previously_downloaded_files=my_reuse_previously_downloaded_files,
                                               local_download_dir_warc=my_local_download_dir_warc,
                                               continue_after_error=my_continue_after_error,
                                               show_download_progress=my_show_download_progress,
                                               number_of_extraction_processes=my_number_of_extraction_processes,
                                               log_level=my_log_level,
                                               delete_warc_after_extraction=True,
                                               continue_process=True)


article = NewsPlease.from_url('https://www.nytimes.com/2017/02/23/us/politics/cpac-stephen-bannon-reince-priebus.html?hp')
print(article.title)

这是运行代码后显示的日志:

  

回溯(最近一次通话最后一次):文件“”,第1行,在      文件   “ /usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py”,   行文件中的699行       execfile(文件名,名称空间)文件“ /usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py”,   execfile中的第88行       exec(compile(open(filename,'rb')。read(),filename,'e​​xec'),名称空间)文件“ /home/owner/Desktop/Codes/Newscrawler.py”,第13行   在       从..crawler导入commoncrawl_crawler作为commoncrawl_crawler SystemError:父模块“未加载,无法执行相对   导入

0 个答案:

没有答案