My python program outputs a set of url links. When I run this on pycharm, I can directly click on the links and that will open them up in the browser. However, when I run the python file by double clicking on the .py file, the links are not clickable. I want the links to be clickable so it takes me to the browser directly.
Please support solutions with explanations as I am still learning. Thanks!
As outlined above, you need to use a terminal that supports clicking of URL's.
On linux, most terminals do this. Ex Gnome-terminal, terminator etc..
On Mac, try iterm2.
Related
I have a button that when clicked copies a link to my clipboard, the problem is that it doesn't do so if I use the headless version of chrome(doesn't show window), that button is the only way I see to access the link. Is there any way to extract the link? The link must be somewhere in the code, but I can't seem to find it
I tried using .sleep thinking that it should do the trick somehow. It didn't
Background:
Programming in Python (vscode)
on Mac
Story:
I am using selenium to automate a process and at some point throughout that process I have to upload a picture. I can click on the "from Computer" button that pops up but this opens the finder with all my files/documents. I do not know how I could tell python here to navigate to a given folder and klick "submit" (or upload).
Question:
Does anyone know a way to "control" the finder similarly to what selenium does for the web browser?
Thank you!
I have tried:
Selenium but it can not handle this (to my knowledge) since I am no longer in the browser.
I have also tried the package pyautogui but because I would like to be able to run the same program from several computers (the path will be the same) but they display the finder differently so I dont think that will do the trick.
I've seen many posts regarding this but all of them in firefox, none of them helps with Chrome. I wanna get access to this download popup window:
Ideally, I'd like to set the download name from the script and then click the save button. But setting the chromedriver to ignore the download dialog and save the images automatically will work as well
Any help will be appreciated
I don't believe you will be able to accomplish this with a python selenium script. The download dialog box is rendered by the browser so you won't be able to target it with HTML.
Alternatively, you can turn off the "download dialog" option in settings that asks you where to save and have it save directly to a directory of your choice and then use python's os module in your script to rename the file.
So if you are saving some file to /tmp for example, then you could do the following in your script after the file has been downloaded:
os.rename("/tmp/my_downloaded_file", "/tmp/my_new_name")
TL;DR: Sublime Text gets a different response from webbrowser._browsers than my terminal.
This has been driving me nuts. I use a plugin, GitLink which will open a GitHub link from your current file. It relies on Python’s webbrowser tool to open the url. The problem is my default browser is Chrome, but it keeps opening Firefox.
In my terminal, if I launch into python or python3, webbrowser.open_new_tab('https://stackoverflow.com') will correctly launch in Chrome. webbrowser._browsers will correctly list 'chrome' as one of my browsers.
However, in the Sublime Text console, webbrowser._browsers is missing Chrome. It lists all the other browser save for the one I actually want. What gives? How is Sublime Text getting a different list than when I run python in my terminal? How do I get it to match?
There are several things you could try.
1. Set the BROWSER environment variable:
As Keith Hall implied this problem might be solved by setting your BROWSER environment variable. If you don't know how look it up for your version - OSX changed how environment variables get set at some point so there are different ways of doing this for different versions of OSX. However, I am on Linux, and my BROWSER environment variable is not set and ST always opens urls in my default browser, this includes calls to webbrowser.open_new_tab() which (as I assume you saw) is what GitLink uses to open urls, so this may not solve the problem.
2. Modify GitLink (your installed version):
First test if this will work - works fine on Linux.
Copy and paste the following 2 lines into the ST console:
import webbrowser
webbrowser.get("chrome").open_new_tab("http://www.google.com")
If that does not open Chrome with Google.com try:
# google-chrome: Chrome variant.
webbrowser.get("google-chrome").open_new_tab("http://www.google.com")
# macosx: uses the OSX default browser.
webbrowser.get("macosx").open_new_tab("http://www.google.com")
# links: generic; doubtful but worth trying at this stage.
webbrowser.get("links").open_new_tab("http://www.google.com")
The full list of possible values may be helpful.
Another possibility is to use the full path instead, see this StackOverflow answer or try:
# Replace path with your path to Chrome if necessary.
webbrowser.register('chrome_path', None, webbrowser.BackgroundBrowser("/Applications/Google Chrome.app"))
webbrowser.get('chrome_path').open_new_tab(url)
Once that is working:
Install the PackageResourceViewer plugin; after it is installed...
Open the Command Palette and select: PackageResourceViewer: Open Resource
In the list of packages select: GitLink
In the list of files select: GitLink.py
The file GitLink.py will open...
If you save this file (nothing will happen at all if you close it without saving) then a copy of GitLink.py will get saved on your system in this location: ST_CONFIG/Packages/GitLink/GitLink.py - this version of the file will override the version of GitLink.py which is stored in the Gitlink.sublime-package file which Package Control would have installed in the Installed Packages folder. Even if the GitLink package gets updated the version in the .sublime-package file will still get overridden. Not a problem, all you need to do to get rid of the changes made is to delete the folder ST_CONFIG/Packages/GitLink/ which contains the GitLink.py file and ST will start using the version from the .sublime-package file again.
The modification is easy:
Scroll down to the bottom of GitLink.py where you will see the lines:
if(args['web']):
webbrowser.open_new_tab(url)
Just change the webbrowser.open_new_tab(url) line to the following (replacing "chrome" if necessary with the value which worked in the console):
if(args['web']):
webbrowser.get("chrome").open_new_tab(url)
Save the file, the plugin should be updated immediately by ST (check the console for the "reloading plugin" message to be sure if you want). The plugin should now open your urls in Chrome.
3. Open an issue on GitLink's GitHub page:
The issue page is here. State your problem and request a setting be added so that users can specify which browser Python's webbrowser module should use.
I suggest you do this anyway and add a link to this StackOverflow page to your issue for reference.
I'm working with project, where previous developer leave many comments with the links on documentation. It's would be very useful, if PyCharm may to follow the links directly from source code. I know that in Visual Studio this feature exist, the links open by CTRL+Click over them. What about PyCharm? I'm using PyCharm Community Edition 3.0.2.
I'm using PyCharm 3.0.2 and Ctrl+Click works for links that starts with http://. But for the links that don't start with http://(i.e. www.example.com), I had to keep the cursor on the link(you don't have to highlight) and the context menu had an option called Open in Browser using which you can navigate to that link in the default browser.
Now, when in comments, the Ctrl+Click is not working even for links with http://. But the second method(Open in Browser from right click context menu on the link) still works so you can still get the job done.