def worker(target_url, ): loop = get_event_loop() article_parser = ArticleParser() res = loop.run_until_complete( article_parser._parse_article(article_url=target_url, )) return res
pass collect() def wash_content(content): """ wash content :param content: :return: """ content = re.compile('<meta name=\"referrer\" content=\"never\">').sub('', content) content = re.compile('<style type=\"text/css\">.*?</style>').sub('', content) return content if __name__ == '__main__': loop = get_event_loop() we_the_media_ops_obj = WeTheMediaOps() article_url = 'https://focus.youth.cn/mobile/detail/id/15711930#' article_parser = ArticleParser() article_res = loop.run_until_complete(article_parser._parse_article( article_url=article_url)) # 待发布内容 title = (article_res['title'] + ' ...')[:29] content = wash_content(article_res['div_body']) # 发布文章 res = loop.run_until_complete(we_the_media_ops_obj._publish_article( publish_article_type='ht', title=title, content=content,))