Python 从网站的交互式图形中删除数据

Python 从网站的交互式图形中删除数据,python,selenium,web-scraping,beautifulsoup,Python,Selenium,Web Scraping,Beautifulsoup,我正在尝试从下面提到的网站访问图表中的数据 我能够从图表下方的表格中访问和提取数据。但是我无法从正在使用javascript动态调用的图形中获取数据?我知道在这里使用beautifulsoup api是不够的。我试着在网页的控制台中查看图表的内容,但没有成功 我还试图研究视图源:如何调用它 <div class="graph" data-testid="graph" data-test="PriceHistoryGraph"&g

我正在尝试从下面提到的网站访问图表中的数据

我能够从图表下方的表格中访问和提取数据。但是我无法从正在使用javascript动态调用的图形中获取数据?我知道在这里使用beautifulsoup api是不够的。我试着在网页的控制台中查看图表的内容,但没有成功

我还试图研究视图源:如何调用它

<div class="graph" data-testid="graph" data-test="PriceHistoryGraph">
我怀疑上述数据可以在

<rect class = "vx-bar" ...... where data="[Object Object][Object Object][Object Object]..." 

任何带有示例或解决方案的建议都会对我有所帮助。提前谢谢

没错,图形是动态构建的,但您可以轻松获取数据

以下是方法:

import requests

response = requests.get('https://www.prisjakt.nu/_internal/graphql?release=2020-11-20T07:33:45Z|db08e4bc&version=6f2bf5&main=product&variables={"id":5183925,"offset":0,"section":"statistics","statisticsTime":"1970-01-02","marketCode":"se","personalizationExcludeCategories":[],"userActions":true,"badges":true,"media":true,"campaign":true,"relatedProducts":true,"campaignDeals":true,"priceHistory":true,"recommendations":true,"campaignId":2,"personalizationClientId":"","pulseEnvironmentId":"sdrn:schibsted:environment:undefined"}').json()


for node in response["data"]["product"]["statistics"]["nodes"]:
    print(f"{node['date']} - {node['lowestPrice']}")
输出:

2019-09-10 - 13195
2019-09-11 - 12990
2019-09-12 - 12990
2019-09-13 - 12605
2019-09-14 - 12605
2019-09-15 - 12605
2019-09-16 - 12970
2019-09-17 - 12970
2019-09-18 - 12970
2019-09-19 - 12969
2019-09-20 - 12969
2019-09-21 - 12969
2019-09-22 - 12969
2019-09-23 - 9195
2019-09-24 - 12970
and so on...

没错,图形是动态构建的,但您可以轻松获取数据

以下是方法:

import requests

response = requests.get('https://www.prisjakt.nu/_internal/graphql?release=2020-11-20T07:33:45Z|db08e4bc&version=6f2bf5&main=product&variables={"id":5183925,"offset":0,"section":"statistics","statisticsTime":"1970-01-02","marketCode":"se","personalizationExcludeCategories":[],"userActions":true,"badges":true,"media":true,"campaign":true,"relatedProducts":true,"campaignDeals":true,"priceHistory":true,"recommendations":true,"campaignId":2,"personalizationClientId":"","pulseEnvironmentId":"sdrn:schibsted:environment:undefined"}').json()


for node in response["data"]["product"]["statistics"]["nodes"]:
    print(f"{node['date']} - {node['lowestPrice']}")
输出:

2019-09-10 - 13195
2019-09-11 - 12990
2019-09-12 - 12990
2019-09-13 - 12605
2019-09-14 - 12605
2019-09-15 - 12605
2019-09-16 - 12970
2019-09-17 - 12970
2019-09-18 - 12970
2019-09-19 - 12969
2019-09-20 - 12969
2019-09-21 - 12969
2019-09-22 - 12969
2019-09-23 - 9195
2019-09-24 - 12970
and so on...

哇,你跑得太快了。事实上,我很高兴作为一个初学者,我看到了正确的地方。但我不知道访问和获取json格式的技术。现在我知道我想知道你是如何找到变量“response”中使用的url的?专业提示:学习使用浏览器的开发工具。我在开发者工具->网络->XHR选项卡中找到了请求链接。我在开发者工具->网络->XHR选项卡->标题中找到了它。谢谢!:)哇,你跑得太快了。事实上,我很高兴作为一个初学者,我看到了正确的地方。但我不知道访问和获取json格式的技术。现在我知道我想知道你是如何找到变量“response”中使用的url的?专业提示:学习使用浏览器的开发工具。我在开发者工具->网络->XHR选项卡中找到了请求链接。我在开发者工具->网络->XHR选项卡->标题中找到了它。谢谢!:)