【问题标题】:Is there a way to speed up this webscraping iteration? Pandas有没有办法加快这种网络抓取迭代?熊猫
【发布时间】:2016-11-16 21:54:41
【问题描述】:

所以我正在收集有关股票列表的数据并将所有这些信息放入数据框中。该名单有大约700只股票。

import pandas as pd

stock =['adma','aapl','fb'] # list has about 700 stocks which I extracted from a pickled dataframe that was storing the info. 

#The site I'm visiting is below with the name of the stock added to the end of the end of the link
##http://finviz.com/quote.ashx?t=adma
##http://finviz.com/quote.ashx?t=aapl

我只是提取该网站的一部分,下面代码中的 [-2] 很明显

df2 = pd.DataFrame()

for i in stock:
    df = pd.read_html('http://finviz.com/quote.ashx?t={}'.format(i), header =0)[-2].set_index('SEC Form 4')
    df['Stock'] = i.upper() # creating a column which has the name of the stock, so I can differentiate between stocks
    df2 = df2.append(df)

感觉每次迭代我都在做几秒钟,而我现在有大约 700 次要完成。它不是很慢,但我只是好奇是否有更有效的方法。谢谢。

【问题讨论】:

  • 查看我的question,或许这对你有帮助。

标签: pandas web-scraping


【解决方案1】:

您当前的代码是阻塞,在您完成当前代码之前,您不会继续从下一个 url 检索信息。相反,您可以切换到例如基于twistedScrapy,并同时异步处理多个页面。

【讨论】:

  • 感谢您的意见。我从未听说过Scrapy。这是现在的 goto web-scraper 吗?有人建议我不久前查看Requests,但我认为Scrapy 现在更受欢迎
猜你喜欢
  • 1970-01-01
  • 2017-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 2013-11-16
相关资源
最近更新 更多