I was just trying to figure out how to get python to see the browser window and read the image there(I don't want to take a snapshot, if possible) process it and then click the relevant button on screen.
As a project I want to avoid selenium. I can't seem to find the correct library or any tutorials for this. Can someone tell me the library and possibly a tutorial?
I am on Ubuntu.
Thanks
Related
I am trying to write a program that goes to the following site and downloads the Excel file that automatically downloads when clicking the XLS button on the bottom of the page. To be honest, I am quite new to programming.
Site: https://echa.europa.eu/assessment-regulatory-needs
At first I tried using Selenium to let the program click itself through the browser and really click on the button. However, I think the website detects the usage of automated software and I cannot bypass the disclaimer that appears when opening the website.
Then I read some answers on the same topic where it is possible by using the requests module. However, I could not get it to work.
One thing I think I understood from this anwer was that you need to get the site/server where the data is requested from by inspecting the button with F12 in the browser. I tried this, and thought I had it, however I cannot get the code to function. I learnt from this answer that you need to give the referer as well, bu I think the referer from this file ist only partially written out, as it is "https://echa.europa.eu/assessment-regulatory-needs".
This answer explained the network process more in detail, howver I am not able to recreate it. Also, to be honest i do not fully understand what the API is and how to search for it.
I also found this answer, but it does not work for me either.
So I am asking for help on this, as I think that my HTML, Java, Website, Python knowledge is too tiny to see what I have to change to be able to download the excel file.
I have had some success automating some work navigating a website lately, but I've had a LOT of difficulty trying to get it to work across multiple systems.
Currently, I am using PyAutoGUI to locate an image of text, and then telling Python to click to the RIGHT of that image in order to select the desired text box. Unfortunately, this isn't panning out to other systems even with lowered confidence intervals for the locateOnScreen() method.
I tried looking into Selenium to locate the text, but unfortunately I would have to run this on an existing IE explorer which is currently unsupported.
I was thinking about using OCR, but I'm unsure of how I would tell Python to click NEXT the the text that I am searching for.
Any input on possible solutions would be greatly appreciated!
-MontX
Edit:
Image of what I've been trying to get PyAutoGUI to recognize.
Example of text I've been trying to locate on screen:
Example of kind of icons I've been trying to locate on screen:
I'd like to ask somebody with experience with headless browsers and python if it's possible to extract box info with distance from closest strike on webpage below. Till now I was using python bs4 but since everything is driven by jQuery here simple download of webpage doesn't work. I found PhantomJS but I wasn't able extract it too so I am not sure if it's possible. Thanks for hints.
https://lxapp.weatherbug.net/v2/lxapp_impl.html?lat=49.13688&lon=16.56522&v=1.2.0
This isn't really a Linux question, it's a StackOverflow question, so I won't go into too much detail.
The thing you want to do can be easily done with Selenium. Selenium has both a headless mode, and a heady mode (where you can watch it open your browser and click on things). The DOM query API is a bit less extensive than bs4, but it does have nice visual query (location on screen) functions. So you would write a Python script that initializes Selenium, goes to your website and interacts with it. You may need to do some image recognition on screenshots at some point. It may be as simple as finding for a certain query image on the screen, or something much more complicated.
You'd have to go through the Selenium tutorials first to see how it works, which would take you 1-2 days. Then figure out what Selenium stuff you can use to do what you want, that depends on luck and whether what you want happens to be easy or hard for that particular website.
Instead of using Selenium, though, I recommend trying to reverse engineer the API. For example, the page you linked to hits https://cmn-lx.pulse.weatherbug.net/data/lightning/v1/spark with parameters like:
_
callback
isGpsLocation
location
locationtype
safetyMessage
shortMessage
units
verbose
authid
timestamp
hash
You can figure out by trial and error which ones you need and what to put in them. You can capture requests from your browser and then read them yourself. Then construct appropriate requests from a Python program and hit their API. It would save you from having to deal with a Web UI designed for humans.
For the website 'https://web-en.wallapop.com/catalog/upload', if one tries to upload an add and scrolls down, photos can also be uploaded. How would I automate the uploading of a photo to this website with python?
I am currently writing a program that automatically creates adds on this website, however I do not know how to automate the uploading of a photo, located in my repository, to the website. I need to interact with the file explorer to pick the image and I do not know how to automate that. I do not even know if that is the right approach.
Any help is greatly appreciated!
driver.find_element_by_xpath('/html/body/tsl-root/tsl-upload/div/div/tsl-upload-product/form/div[2]/tsl-drop-area/div/div[2]/div/div[2]/label/input').send_keys(r'C:\Users\Nicolas Sanchez\3D Objects\Freelancer\Alberto\imagenes\i1473749533.jpg')
This works. This was my first thought initially however I was picking the wrong xpath selectors. This is the right xpath selector.
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.