Use existing open tab and url in Selenium py - python

Hi I'm trying to use Selenium python to use a url that is already open on Internet Explorer. I had a look around and not sure if this is possible.
The reason why I wouldn't like to open new brower or tab is because the page changes to different text.
So far my text only opens a new browser
CODE
from selenium import webdriver
driver = webdriver.Ie()
driver.get("https://outlook.live.com/owa/")

This answer helped me with same problem.
By now you can not access previously opened tabs with selenium.
But you can try to recreate your session, passing what is needed using requests library, for example.

Related

How to play a Youtube video in python

What modules should I use to make a Python script where Python gets the name of a video, opens up a Chrome window, opens Youtube and plays the first result. I've tried Youtube Data API but it's not for that kind of things.
You can use the subprocess to call a browser and run the url you request. With this minimal code you can ask for a website to go, and open in firefox. But you can use it as a bootstrap code for your application using chrome.
import subprocess
url = input('What site you would to go: ')
subprocess.Popen(['firefox',url])
Using this template, you can just change the code to ask for a youtube link. If you have firefox installed you can just run it.
from selenium import webdriver
# You could also use Chrome, I just default to Firefox
driver = webdriver.Firefox()
driver.get('URL within some quotes')
# And if you want full-screen, finish it off with
driver.maximize_window()
And boom, that's a really quick way to open a site. You need to pip install selenium, of course, but this is my preferred way. Just wanted to offer an additional option.

Getting the current url in the browser

I am trying to get the current url opened in my pc in any browser using python.
I tried selenium it worked but it opens up a new browser window. I only want to get the current url opened in the browser.
Any help would be appreciated.
use keylogger in python, that would easiest solution, orelse you should catch each and every packets in network.
Selenium isn't made for such purposes. It can be used to automate testing of websites or for website scraping. Selenium associated with a driver (like Chrome's driver for example) is just a fancy browser that let's you interact with it in a non-intrusive way.
If you need to interact with already running apps, you could attach to another process's memory and read stuff directly from there but it might be very messy.
Also, see: Interact with other programs using Python

How do I input information into a website with python?

I have this python code, which accesses a website using the module webbrowser:
import webbrowser
webbrowser.open('kahoot.it')
How could I input information into a text box on this website?
I suggest you use Selenium for that matter.
Here is an example code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# driver = webdriver.Firefox() # Use this if you prefer Firefox.
driver = webdriver.Chrome()
driver.get('http://www.google.com/')
search_input = driver.find_elements_by_css_selector('input.gLFyf.gsfi')[0]
search_input.send_keys('some search string' + Keys.RETURN)
You can use Selenium better if you know HTML and CSS well. Knowing Javascript/JQuery may help too.
You need the specific webdriver to run it properly:
GeckoDriver (Firefox)
Chrome
There are other webdrivers available, but one of the previous should be enough for you.
On Windows, you should have the executable on the same folder as your code. On Ubuntu, you should copy the webdriver file to /usr/local/bin/
You can use Selenium not only to input information, but also to a lot of other utilities.
I don't think that's doable with the webbrowser module, I suggest you take a look at Selenium
How to use Selenium with Python?
Depending on how complex (interactive, reliant on scripts, ...) your activity is, you can use requests or, as others have suggested, selenium.
Requests allows you to send and get basic data from websites, you would probably use this when automatically submitting an order form, querying an API, checking if a page has ben updated, ...
Selenium gives you programmatic control of a "normal" browser, this seems better for you specific use-case.
The webbrowser module is actually only (more or less) able to open a browser. You can use this if you want to open a link from inside your application.

Using Python, is there a way to create a new tab and navigate to a site in an active Chrome browser?

I know I can use Selenium, but that opens a new browser window which isn't what I want. I would like to access the browser window I am already using and open a new tab with the domain/url I'm trying to load.
Maybe you are looking for this: https://docs.python.org/2/library/webbrowser.html
This will open a new tab in default browser.
My Apologies, i dont have enough reputation to comment yet.
I just tested the following code in my computer and opened a new tab in my default browser (Chrome in my case):
import webbrowser
webbrowser.open_new('http://www.google.com')
If you want to open a new tab in a non-default browser you will have to do the following:
import webbrowser
b = webbrowser.get('Safari') # Or the path to the browser you want to use
b.open_new('http://www.google.com')

Is there a way to use Python to check the url of the currently opened browser?

I wanted to write a program that continuously checks the URL of a browser (e.g. Chrome) and if it is equal to www.youtube.com, then I want to switch the URL. I'm stuck on trying to find a way to check the URL of a currently opened browser. Is the webbrowser module only for opening new browsers?
Edit: What I've tried so far is webbrowser:
import webbrowser
webbrowser.open('www.youtube.com')

Categories

Resources