I want to automatically log in to a website using Python's webbrowser I made a lot of trial and error, so I will leave it as a memorandum.
macOS high sierra 10.13.6 python Python 3.7.3
web_open.py
import webbrowser
webbrowser.open("URL you want to open")
It opened safely. If you want to specify the browser, it seems to be specified by get ().
I want to input keyboard input as it is and use pyautogui.
web_login1.py
import webbrowser
import pyautogui
import time
#Open browser
webbrowser.open("URL you want to open")
#Sleep just in case
time.sleep(1)
#Store login ID and password
mail_address = "hoge"
passwd = "hoge"
#Go to the box to enter your login ID
pyautogui.press('enter')
pyautogui.press('tab')
pyautogui.press('tab')
pyautogui.press('tab')
#Enter your email address
for i in range(0,len(mail_address)):
pyautogui.press(mail_address[i])
#Go to password entry
pyautogui.press('tab')
#Enter password
for i in range(0,len(passwd)):
pyautogui.press(passwd[i])
#Login
pyautogui.press('enter')
Here, the "@" included in the email address has been replaced with another symbol. If it is windows, it seems that it can be solved by adding various things to the pyautogui file. I couldn't find a solution for macOS, so I considered another method.
If you look for various things, it seems that you can solve it with pyperclip.
web_login2.py
import webbrowser
import pyautogui
import pyperclip
import time
webbrowser.open("URL you want to open")
#Sleep just in case
time.sleep(1)
#Store login ID and password
mail_address = "hoge"
passwd = "hoge"
#Go to the box to enter your login ID
pyautogui.press('enter')
pyautogui.press('tab')
pyautogui.press('tab')
pyautogui.press('tab')
#copy
pyperclip.copy(mail_address)
#paste
pyautogui.hotkey("command","v")
#Go to password entry
pyautogui.press('tab')
#copy
pyperclip.copy(passwd)
#paste
pyautogui.hotkey("command","v")
#Login
pyautogui.press('enter')
I want to do this with Raspberry Pi, but I wonder if it works on linux.
Recommended Posts