Possibility to extract the data from Canvas/Image/Charts #278
Replies: 1 comment
-
|
You can't read canvas from the DOM, the pixels live in the GPU. But the data behind the chart is usually grabbable somewhere else. If the page fetches the data from an API (most do), use Scrapling's from scrapling.fetchers import DynamicFetcher
captured = {}
def dump(page):
captured["data"] = page.evaluate("""() => {
const c = document.querySelector('canvas');
if (window.Chart?.getChart) return Chart.getChart(c)?.data;
if (window.Highcharts) return Highcharts.charts.map(x => x?.options?.series);
return null;
}""")
DynamicFetcher.fetch(URL, page_action=dump, network_idle=True)
print(captured["data"])Heads up: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I was just wondering if this tool can extract the data (Only from the DOM) that is rendered by canvas in the page?
Not by Screenshot and sending it to the Agent but just extract the exact data from the page, which may contain the plots that are rendered in the canvas tag
Beta Was this translation helpful? Give feedback.
All reactions