简体   繁体   English

为什么我在抓取实时数据时得到一个空列表?

[英]why am i getting an empty list when scrapping realtime data?

I am trying toscrape some financial data but i keep getting empty lists whenever i use selenium or beautiful soup我正在尝试抓取一些财务数据,但是每当我使用硒或美丽的汤时,我都会得到空列表

this is the code i used with selenium这是我与硒一起使用的代码

driver = webdriver.Chrome(os.getcwd() + '/chromedriver')
driver.get("https://www.amarkets.com/research-education/sentiment-widget/")
time.sleep(3)

real_soup = BeautifulSoup(driver.page_source, 'html.parser')
sentiments = real_soup.findAll("TD")
print(sentiments)

i keep getting an empty list.我不断得到一个空列表。

Don't scrape it - use the api (which you can find by checking network activity ):不要刮它 - 使用 api(您可以通过检查网络活动找到):

import requests
import pandas as pd

r = requests.get('https://api.prod.amarkets.dev/v1/sentiment-widget-dev/?request=%7B%22Symbols%22%3A%5B%22EURUSD%22%2C%22GBPUSD%22%2C%22USDJPY%22%2C%22AUDUSD%22%2C%22NZDUSD%22%2C%22USDCAD%22%2C%22USDCHF%22%2C%22EURJPY%22%2C%22EURGBP%22%2C%22XAUUSD%22%2C%22XAGUSD%22%2C%22DowJones30%22%2C%22S%26P500%22%2C%22Nasdaq100%22%2C%22BTCUSD%22%2C%22BRENT%22%5D%2C%22NodesType%22%3A%22Real%22%2C%22CollectSuffixes%22%3Atrue%2C%22RequestName%22%3A%22RequestWidgetSentiments%22%7D')
df = pd.DataFrame(r.json()['Result'])

Result:结果:

Symbol象征 Time时间 Bid出价 Ask Digits数字 Spread传播 MinSpread最小点差 Buyers买家 Sellers卖家 VolumeBuyInUsd成交量买入美元 VolumeSellInUsd成交量卖出美元
0 0 AUDUSD澳元兑美元 2021-11-10 17:57:39:216 2021-11-10 17:57:39:216 0.73826 0.73826 0.73852 0.73852 5 5 2.6 2.6 2.1 2.1 127 127 126 126 901424 901424 1.00069e+06 1.00069e+06
1 1 BRENT布伦特 2021-11-10 17:57:39:216 2021-11-10 17:57:39:216 84.88 84.88 84.91 84.91 2 2 3 3 3 3 84 84 159 159 1.1943e+06 1.1943e+06 1.82476e+06 1.82476e+06
2 2 BTCUSD比特币美元 2021-11-10 17:57:39:216 2021-11-10 17:57:39:216 68344 68344 68374.3 68374.3 2 2 3024 3024 1243 1243 86 86 87 87 189964 189964 341095 341095
3 3 DowJones30道琼斯30 2021-11-10 17:57:39:216 2021-11-10 17:57:39:216 36215 36215 36223 36223 0 0 8 8 7 7 40 40 75 75 262533 262533 2.2185e+06 2.2185e+06
4 4 EURGBP欧洲RGBP 2021-11-10 17:57:39:216 2021-11-10 17:57:39:216 0.85477 0.85477 0.8549 0.8549 5 5 1.3 1.3 1.3 1.3 65 65 89 89 454269 454269 890184 890184

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM