网页协助 [英] Webscraping assistance

查看:62
本文介绍了网页协助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从该网页中提取一些信息.我知道有获取这些信息的简便方法,但这正是我的任务.到目前为止,我一直在尝试:

I have to extract some info from this web page. I know there are easier ways of obtaining this information yet this is what I am tasked with. So far, I have been trying this:

import pandas as pd
import requests
from bs4 import BeautifulSoup

url = 'https://www.nasdaq.com/market-activity/funds-and-etfs/qqq/historical'
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')

在这里,我尝试使用以下方法将其直接读取到Pandas DataFrame中:

From here I am trying to read this directly into a Pandas DataFrame using:

df = pd.read_html(str(soup.select('historical-data__table')))

但是,我遇到此错误:


  File "<ipython-input-94-f3a234b1eafd>", line 1, in <module>
    df = pd.read_html(str(soup.select('historical-data__table')))

  File "C:\Anaconda3\lib\site-packages\pandas\io\html.py", line 1094, in read_html
    displayed_only=displayed_only)

  File "C:\Anaconda3\lib\site-packages\pandas\io\html.py", line 916, in _parse
    raise_with_traceback(retained)

  File "C:\Anaconda3\lib\site-packages\pandas\compat\__init__.py", line 420, in raise_with_traceback
    raise exc.with_traceback(traceback)

ValueError: No tables found

任何帮助将不胜感激.

推荐答案

此数据来自您可以直接使用:

import requests

response = requests.get(
    'https://api.nasdaq.com/api/quote/QQQ/historical',
    params = {
        'assetclass':'etf',
        'fromdate':'2019-09-11',
        'todate': '2019-10-11',
        'limit': 18
    }
)
print(response.json()['data']['tradesTable']['rows'])

这篇关于网页协助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆