当运行下面的代码时,我从IDLE运行代码时得到'None‘输出,但从我的命令提示符运行时我得到全文输出(正确的输出)。为什么会这样呢?我是否错误地使用了池?
测试多进程
从多进程导入池
import requests
from bs4 import BeautifulSoup
import re
def scrape_ticker(url):
response = requests.get(url)
Soup = BeautifulSoup(response.content, 'html.parser')
for i in Soup.find_all('p'):
print(i.get_text())
if __name__ == '__main__' :
urls = ['http://www.investopedia.com/investing/biotech-stocks/',
'https://www.fool.com/investing/2017/06/25/5-best-biotech-stocks-of-2017-so-far.aspx',
'http://www.marketwatch.com/story/five-reasons-you-have-to-buy-biotech-stocks-now-2017-06-20',
'http://www.kiplinger.com/slideshow/investing/T052-S003-7-battered-biotech-stocks-to-buy/index.html',
'http://www.investors.com/research/ibd-stock-analysis/exelexis-biotech-stock-with-497-growth-positive-trial-results-nears-buy-zone-celgene-climbs/']
pool = Pool(processes=2)
print(pool.map(scrape_ticker, urls))发布于 2017-08-10 04:08:34
您正确地使用了Pool.map。然而,众所周知的问题是,multiprocessing.Pool不能与IDLE这样的交互式解释器一起工作。这是记录在示例下面的here。
https://stackoverflow.com/questions/45355390
复制相似问题