Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
there
I'm trying to make a Robotic Process Automation(called RPA) using python.
There are two windows; one is excel and the other is web.
The Procedure is:
Both excel and web must be opened before run the code(It never be changed, there are no alternatives)
the data on the web is copied and pasted to excel file.
done!
It looks easy... but, selenium cannot access to already opened web and cannot access to already opened excel file.
of course, it could be easy to access to new web and new or load excel.
It doesn't matter selenium and are not used.
Does somebody know how to solve it??
Thank you.
I see what you are trying to do, but there are easier ways to do this. Some questions to consider:
1. Is selenium the right tool for the job?
Do you need to simulate an entire browser navigate and download the file, or can you use some code to more simply download the file? Simulating the browser seems like a good idea until you notice you can simply scrape the website.
Using something like requests to download a webpage and something like BeautifulSoup to extract the specific link for the .xlsx, you can perhaps more easily achieve what you are looking for.
If selenium is indeed needed you should look into how to download the file -- not copy and paste it into Excel. Copying the file from the browser will require you to figure out some things like how to paste it on Excel, and extract individual HTML tags... which I bet will be inconceivably hard.
2. Do you wish to modify the.xlsx file?
If not, you should simply download it to a specific directory in your computer, and open the file on Excel with Python. If yes, then you will have to look into tools like pandas.
Don't give up.
If you looking to get this project to work you gotta keep in mind that programming is 65%-70% research and 25%-30% actually programming. The above resources should get you started, but it is vague enough that you will have to do your own research to get it going.
As per my knowledge, selenium will only interact with those windows, that are invoked by it, but not on those which were already open. But, here are some related threads said we could do it using remote WebDriver and Session ID, you could check them:
How can I reconnect to the browser opened by webdriver with selenium?
Re-using existing browser session in selenium
Can Selenium interact with an existing browser session?
From my point of view, if you want to access the already opened IE window and Excel Worksheet, I suggest you could try to use VBA.
More detail information, please check the following articles:
Understanding automation
Excel + VBA + IE = web automation
How do I set the value to an already open Excel workbook?
How to navigate to an already opened internet explorer window? (VBA)
Related
I have a problem. Let's say I have a website (e.g. www.google.com). Is there any way to create a file with a .url extension linking to this website in python? (I am currently looking for a flat, and I am trying to save shortcuts on my hard drive only to apartment offers posted online matching my expectations ) I've tried to use the os and requests module to create such files, but with no success. I would really appreciate the help. (I am using python 3.9.6 on Windows 10)
This is pretty straightforward. I had no idea what .URL files were before seeing this post, so I decided to drag its URL to my desktop. It created a file with the following contents which I viewed in Notepad:
[InternetShortcut]
URL=https://stackoverflow.com/questions/68304057/internet-shortcut-in-python
So, you just need to write out the same thing via Python, except replace the URL with the one you want:
test_url = r'https://www.google.com/'
with open('Google.url','w') as f:
f.write(f"""[InternetShortcut]
URL={test_url}
""")
With regards to your current attempts:
I've tried to use os and requests module to create such file
It's not clear what you're using requests or os for, since you didn't provide a Minimal Reproduceable Example of what you'd tried so far; so, if there's a more complex element to this that you didn't specify, such as automatically generating the file while you're in your browser, or something like that, then you need to update your question to include all of your requirements.
The website Download the GLEIF Golden Copy and Delta Files.
has buttons that download data that I want to retrieve automatically with a python script. Usually when I want to download a file, I use mget or similar, but that will not work here (at least I don't think it will).
For some reason I cannot fathom, the producers of the data seem to want to force one to manually download the files. I really need to automate this to reduce the number of steps for my users (and frankly for me), since there are a great many files in addition to these and I want to automate as many as possible (all of them).
So my question is this - is there some kind of python package for doing this sort of thing? If not a python package, is there perhaps some other tool that is useful for it? I have to believe this is a common annoyance.
Yup, you can use BeautifulSoup to scrape the URLs then download them with requests.
I have spent a lot of time searching for an answer to this, but have not found anything yet.
Are there any Tableau packages for R? I would like to be able to create Tableau charts (or a tde file) as an output from my R script. It seems like you can run some basic R scripts from within Tableau, but that will not work for my case.
This is one of the few links I have found relevant to what I am looking for:
R-bloggers link
Would it matter if I were trying to go from Python -> Tableau?
While there are options for creating TDEs (as you've already found) and for working administration of Tableau Server, at the moment there are no open interfaces for creating Tableau workbooks from outside of Tableau proper. This is currently one of my biggest annoyances with the software.
The closest you're going to be able to get is to use the Python Tableau Document API (https://github.com/tableau/document-api-python). While that does not allow creating workbooks from scratch, it does have the most robust document editing capabilities of the various options (https://community.tableau.com/community/developers) available. The README on the Python doc API suggest that document creation may be coming. Sounds like something to watch.
I am using TimeStats extension on Chrome. And what I want to do now is to read the data in the LocalStorage (which contains all the information about the time I spent on each website) in a Python script and do later data processing.
I know that Ctrl+c and Ctrl+v would work in this case, but I am wondering are there any elegent and reliable ways to do that?
Thanks!
You can use native messaging to send data between your extension and an external app. The sample app for demonstrating native messaging is written in Python, so you have the communications part already solved.
EDIT:
I see now that you are talking about an extension you don't own. Google Chrome currently stores LocalStorage data in SQLite format, so you should be able to read it directly using the sqlite3 package. See the answers to this question.
The file for the timeStats extension would be chrome-extension_ejifodhjoeeenihgfpjijjmpomaphmah_0.localstorage
Note that Google can change the way of storing LocalStorage at any time.
I have a problem with links on my website. Please forgive me if this is asked somewhere else, but I have no idea how to search for this.
A little background on the current situation:
I've created a python program that randomly generates planets for a sci-fi game. Each created planet is placed in a text file to be viewed at a later time. The program asks the user how many planets he/she wants to create and makes that many text files. Then, after all the planets are created, the program zips all the files into a file 'worlds.zip'. A link is then provided to the user to download the zip file.
The problem:
The first time I run this everything works perfectly fine. When run a second time, however, and I click the link to download the zip file it gives me the exact same zip file as I got the first time. When I ftp in and download the zip file directly I get the correct zip file, despite the link still being bad.
Things I've tried:
When I refresh the page the link is still bad. When I delete all my browser history the link is still bad. I've tried a different browser and that didn't work. I've attempted to delete the file from the web server and that didn't solve the problem. Changing the html file providing the link worked once, but didn't work a second time.
Simplified Question:
How can I get a link on my web page to update to the correct file?
I've spent all day trying to fix this. I don't mind looking up information or reading articles and links, but I don't know how to search for this, so even if you guys just give me links to other sites I'll be happy (although directly answering my question will always be appreciated :)).
I don't know anything about Python, but in PHP, in some fopen modes, if a file is trying to be made with the same name as an existing file, it will cancel the operation.