click to javascript button with python - python

I want write a bot for steam trade. But i cant found example for it with python. I think if i can click a button with python i can do it. Is it true?
If i can click "Accept Trade" button its fine.
I can scrap source with beautifulsoup library but I couldn't any user operation with it.
Here is accept button's source code:
<div id="trade_confirmbtn" class="trade_confirmbtn ellipsis" onclick="ConfirmTradeOffer();">
And here is trade page link hierarchy:
https://steamcommunity.com/tradeoffer/{{tradeid}}/
I have not a code yet. Thank you!

Selenium is a python module that can interact with web-page resources, so that's an easy way to execute JavaScript code from within Python.

Related

Get current HTML from browser tab with Python

I know there are plenty ways to get a HTML source passing the page url.
But is there a way to get the current html of a page if it displays data after some action ?
For example: A simple html page with a button (thats the source html) that displays random data when you click it.
Thanks
I believe you're looking for a tool collectively known as a "headless browser". The only one I've used that is available in Python (and can vouch for) is Selenium WebDriver, but there are plenty to choose from if you're searching up headless browsers for Python.
https://pypi.org/project/selenium
With this you should be able to programmatically load a web page, look up and click the button in the virtually rendered DOM, then lookup the innerHTML property of the targeted element.

Python - Browser Automation - MechanicalSoup/ BeautifulSoup

I am attempting to automate a button push that prompts javascript on my own website(godaddy server). I am running a .py from my MAC OS Terminal.
I have found beautiful soup and mechancial soup but only found documentation for parsing text or prefilling forms.
I have attempted mechanical soup code absent any 'form' mention, and merely trying to click a button based on a css selector.
I have played around with this code for a few hours and am not convinced what I want to accomplish is possible. Can anyone confirm this is possible with either of these modules? If not, what is a better tool?
I have just been using the example provided here: https://mechanicalsoup.readthedocs.io/en/stable/tutorial.html#first-contact-step-by-step
my code in a function:
def updatePrices()
br = mechanicalsoup.StatefulBrowser()
br.open("http://example.com")
br.get_current_page().find('button', id='exporter_decisionStream')
br.submit_selected()
updatePrices()
Any guidance is appreciated.
Thanks.

Interact with webpage Beautifulsoup and python

I'm using Python 2.7 with beautifulsoup and urllib2, I'm trying to scrap this page: angel.co/companies
As you see it shows a list with companies and it ends with a button "More" to show the others. As you click the button, more companies appear to watch and it creates a new tag with the new list of resutls. The button is in this div: <div class="more" data-page="2">More</div> and each time you click it the data-page increases.
I'd like to know if it's possible to scrap this page completely (so it clicks the "More" button each time it arrives to the end). I suppose it is scrapping the css and changing it but I never did so and I haven't found information about this anywhere.
Depending on what you want to do you could use their API for this. If you are not sure what it is and how to use it, try googling around for an answer. Here's one for starters.

Uploading a file into a popup window with selenium

I have searched the forums and found some information regarding this, but not quite with the problem I'm facing. I am automating the uploading of files to a website. Unfortunately, the website uses a counter for the id of the "browse" button. Using Selenium and Firebug, I was able to find another way to identify the button. I have exported the script into python to add variables so I can automate. However, the browse button opens a windows popup to select the file. The script is started out like this...
driver.find_element_by_xpath("//*[#type=\"file\"]").click()
driver.find_element_by_id("upfile_1405369589849").clear()
driver.find_element_by_id("upfile_1405369589849").send_keys("path\\file")
driver.find_element_by_id("upload_button").click()
In this, the upload button is clicked, the popup appears, and it sits there mocking me. I tried using the xpath in place of the id, but that didn't work. I tried the following, too...
driver.findElement(By.id()).send_keys("path\\file")
and tried this...
driver.find_element_by_id("upfile_*").send_keys("path\\file")
I cant seem to get the window to respond, other than it's mocking glare. Any help to squelch this would be very appreciated.
It can´t be done. One workaround is to get the development team to modify the AUT for you. Add a javascipt function into the page that will allow you to pass the filename to the handler without having to click the browse button.
If you can´t do that, I would suggest that you look into Sikuli that will allow you to interact with the windows prompt using pattern recognition (screenshots) of what you want to interact with.

how to trigger a button in HTML using python?

I want to trigger a button of a html file.
There is a web site in which there are number of options and a button.
After clicking on the button, using the options, a html table is created on next page.
I want to automate the process but I dont know how I can trigger a button using python.
DO anyone knows about the same?
You can use windmill, mechanize or selenium RC.

Categories

Resources