I am trying to get the actual user agent that I am using in Selenium, at the moment with the chromedriver.
I found a Java version of this problem:
How to get userAgent information in Selenium Web driver.
Does someone know how to do that in Python?
The same manner as inside your link:
user_agent = driver.execute_script("return navigator.userAgent;")
PS: Using execute_script method you can run JS inside your driver.
Hope it helps you!
Related
I am trying to make an auto yt searcher and this is as far as I got. I don't really understand on how to user selenium so I am using web-browser what's currently not happening is it is not opening or searching on the search bar (I used the XPath)or does anyone know a tutorial for selenium
import webbrowser
import time
url = 'http://youtube.com'
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(url)
LastName = "nice"
time.sleep(2)
last = webbrowser.open('//*[#id="search"]')
webbrowser.get(LastName)
You can't use the actual Google Chrome Browser.
Instead you have to use ChromeDriver that works the same as the standard Chrome but you can use it with selenium.
You can download it here.
Once installed specify the correct path of chromedriver.
Python webbrowser module is not intended for interaction with UI objects. The purpose is just to open browser in order to display arbitrary web document from your python code.
If you check this module page you will know that webbrowser.open(...) takes the URL as a parameter. It cannot work with xpath or other types of selectors. It cannot send other types of commands to browser except of "open that page".
So you have to deal with webdriver.
I would highly recomend to use selenium, because it is not very hard to learn and to integrate.
from selenium import webdriver
api = webdriver.Firefox()
api.get("https://www.youtube.com")
elem = api.find_elements_by_id("search")[1]
elem.send_keys("Your Search")
elem.submit()
Here you only have to change search and it works. Just download firefox and the geckodriver put the geckodriver in the same directory as the script and tadah it should work.
I'm learning how selenium crawls data, but I find that when a website opens through selenium, it's different from what I used to get when I used other normal browsers. Even I add headers. And I'm very confused.
I really want to upload two contrast pictures, but I can't upload them in stackoverflow at present. I even tried to open the chrome driver and enter the web address manually, but the result is still different.
I use Python 3.6, selenium and chrome 75.0.3770.80
from selenium import webdriver
driver = webdriver.Chrome() #创建driver实例
url = 'https://www.free-ss.ooo'
driver.get(url)
At present, I can't post pictures on stack overflow, but I just want to figure out how I can use selenium to get normal web pages.
Aha,I found the problem, really because the target site detected selenium, the solution is to add options
Chrome_options. add_experiment_option ('excludeSwitches', ['enable-automation'])
Faced same issue and was able to resolve it by removing or fixing appropriate user-agent argument and it worked fine in both headless and non-headless mode.
The resolution was inspired by PDHide post
This is the site that I want to login into: https://nid.naver.com/nidlogin.login
When I tried to log in this site using selenium webdriver, it showed CAPTCHA.
But when I type id/pw by myself, keyboard typing, the CAPTCHA didn't show up!
How can selenium driver be detected?
It depends on your driver. Chromedriver does set specific js variables when it starts the browser. I'm sure other driver vendors have something similar. So, in short, yes. There are different ways it can determine that you are running via webdriver.
I am writing a python script which includes opening up an URL and do some activity on it. I am facing an issue when i execute below code then Firefox browser starts but it is not able to browse URL. What could be wrong here..?
I also tried to add proxy exception but that isn't solve issue.
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('WEBSITE_URL')
So, Pls suggest what is wrong here.
I am working on a project that does online homework automatically.
I am able to login, finding exercises and even filling the form using mechanize.
I discovered that the submit button trigger a javascript function and I searched for the solution. A lot of answers consist of 'simulating the XHR'. But none of them talked about the details.
I don't know if this screen cap helps.
http://i.stack.imgur.com/0g83g.png
Thanks
If you want to evaluate javascript, I'd recommend using Selenium. It will open a browser which you can then send text to it from python.
First, install Selenium: https://pypi.python.org/pypi/selenium
Then download the chrome driver from here: https://code.google.com/p/chromedriver/downloads/list
Put the binary in the same folder as the python script you're writing. (Or add it to the path or whatever, more information here: https://code.google.com/p/selenium/wiki/ChromeDriver)
Afterwards the following example should work:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()
More information here
(The example was also from there)
A xhr is the same as a regular request. Make it the same way and then deal with the response.