简体   繁体   English

web 如何使用 python 美丽的汤刮取仅出现在鼠标 hover 上的数据?

[英]How to web scrape data which only appears on mouse hover using python beautiful soup?

So I am working on a project and on this link: https://www.nasdaq.com/market-activity/stocks/aapl/earnings所以我正在做一个项目,并在这个链接上工作: https://www.nasdaq.com/market-activity/stocks/aapl/earnings

I am able to extract all table data easily by normal beautiful soup method.我可以通过普通的美汤方法轻松提取所有表格数据。 However, on the site, there is a graph, and that data I need only comes when you hover your cursor over it.但是,在网站上,有一个图表,我需要的数据只有当你 hover 你的 cursor 超过它时才会出现。 My issue is simple, how do you extract that?我的问题很简单,你如何提取它? Because when I go to inspect source code of the site on the barchart, I only get the css part of it and the length of the bar and all, not the actual data of estimated and reported EPS which appears on the mouse hover.因为当我 go 在条形图上查看该站点的源代码时,我只得到了它的 css 部分和条形的长度以及全部,而不是出现在鼠标 ZE0542F579DF8E8BFFFADE6 上的估计和报告的 EPS 的实际数据。 I wish I could我希望我能



try:
        divparent = soup.find_all('div', attrs={'class':'highcharts-point highcharts-color-0     highcharts-point-mouseOut'})
except:
    print("no table div")
    return 

I tried to do the code above, but to no avail, and I have literally no idea how to go about this.我尝试执行上面的代码,但无济于事,我真的不知道如何 go 解决这个问题。 Any assistance for this would be greatly appreciated.对此的任何帮助将不胜感激。 Thank you.谢谢你。

This data is being added to the page using JavaScript, and is not in the response you got with the request to https://www.nasdaq.com/market-activity/stocks/aapl/earnings .此数据正在使用 JavaScript 添加到页面中,并且不在您收到https 请求的响应中://www.nasdaq.com/market-activity/stocks/aapl/earnings

However, you can get it using the API (this is what the JavaScript code does).但是,您可以使用 API 获得它(这是 JavaScript 代码所做的)。 Just send your get request to: https://api.nasdaq.com/api/quote/AAPL/eps只需将您的获取请求发送至: https://api.nasdaq.com/api/quote/AAPL/eps

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

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