Operate your website with Python_Webbrowser

Thing you want to do

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.

environment

macOS high sierra 10.13.6 python Python 3.7.3

Open browser

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 ().

log in

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.

Solved using pyperclip

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

Operate your website with Python_Webbrowser
Publish your website with responder + Gunicorn + Apache
Operate Kinesis with Python
Operate Blender with Python
Operate Excel with Python (1)
Operate Excel with Python (2)
Operate your PC with a webcam II. [Goodbye mouse! ]
Visualize fluctuations in numbers on your website with Datadog
Operate Excel with Python openpyxl
Operate Db2 container with Go
Operate TwitterBot with Lambda, Python
Minimal website environment with django
[Note] Operate MongoDB with Python
[Python] [SQLite3] Operate SQLite with Python (Basic)
ROS course 105 Operate toio with ROS
Operate Nutanix with REST API Part 2
Operate a receipt printer with python
Try to operate Facebook with Python
Operate ECHONET Lite appliances with Python
Operate Maya with OSC from vvvv
Train UGATIT with your own dataset
Manage your data with AWS RDS
Website scraping with Python's Beautiful Soup
Solve your own maze with DQN
Operate Linux Network Namespace with Go