Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click a webpage button without going on the webpage

I am attempting to semi-automate my department's workflow, and part of it includes this project I'm doing. The sections I am currently struggling with is "clicking" a button on a webpage.

The webpage has data in a grid (looks like an Excel sheet) and has multiple pages that I want to parse out and use as data for the automation, and there is a button on the webpage that, when clicked, converts all the pages of that data into an Excel sheet and saves it where I need on my computer. I want to constantly update that Excel sheet with the changes as more data is added to the webpage.

However, I do not want to always have that webpage open and have automatic button presses that constantly saves the webpage to Excel. Rather, I want to have it running "in the background" so the only progress I see is the Excel sheet getting updated. Is there a way to "click" that 'Convert to Excel' button without actually going on the webpage to do it?

I was looking at Python libraries like Requests and bs4, but I'm not sure which methods might be applicable for this, if those are even what I should be looking for.

like image 975
Kirby Forsberg Avatar asked Jul 23 '19 14:07

Kirby Forsberg


2 Answers

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://example.com")
button = driver.find_element_by_id('buttonID')
button.click()
like image 107
GolovDanil Avatar answered Oct 17 '22 14:10

GolovDanil


What you want is called a robot and for Python I highly recommend looking into Selenium. Just google for python selenium tutorial or start by reading this: https://selenium-python.readthedocs.io/getting-started.html#simple-usage

like image 37
bkd Avatar answered Oct 17 '22 15:10

bkd