简体   繁体   English

查找下载网址或自动触发按钮单击事件的方法

[英]Finding a download url, or way to automatically trigger button click event

ON this page: https://razzball.com/mlbhittingstats/ , there is an option to get the CSV data of the page as a download. 在此页面上: https : //razzball.com/mlbhittingstats/ ,有一个选项可以下载该页面的CSV数据。 What I am wondering, is if there is a way to trigger this programatically.. 我想知道的是,是否有一种方法可以以编程方式触发此操作。

I figure that button has to be pointing towards some url or some function and there is a way to call it. 我认为按钮必须指向某个url或某些函数,并且有一种调用它的方法。 Otherwise I feel like I would have to use a webdriver and somehow click the button. 否则,我觉得我将不得不使用网络驱动程序并以某种方式单击该按钮。 Is this possible? 这可能吗? Or do I have to use a headless, automated browser 还是我必须使用无头自动浏览器

This "Export to CSV" feature is entirely javascript-based/client-side - the table is a implemented using the jQuery tablesorter library. 此“导出为CSV”功能完全基于javascript /客户端-该表是使用jQuery tablesorter库实现的。

In order to do the "export" you would need a way to execute JavaScript in the context of the rendered page - arguably the easiest way to do it would be to use selenium to simply click the button, but you can also do trigger the "export to csv" programmatically which allow for options like Splash . 为了进行“导出”,您需要一种在呈现的页面的上下文中执行JavaScript的方法-可以说,最简单的方法是使用selenium来简单地单击按钮,但是您也可以触发“以编程方式导出到csv” ,允许使用诸如Splash之类的选项。

If you go "selenium route", make sure to allow CSV files to be downloaded automatically: 如果您使用“硒路线”,请确保允许自动下载CSV文件:


Another alternative idea would probably be to do the CSV exporting on your own - for instance, using pandas library and its read_html() to HTML parse the table and to_csv() to dump a DataFrame into CSV. 另一个替代方法可能是自己进行CSV导出-例如,使用pandas库及其read_html()对表进行HTML解析,并使用to_csv()将DataFrame转储为CSV。

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

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