Log in to Yahoo Business with Selenium Python

Hundreds of Yahoo Business IDs and passwords. Is it possible to log in with this Excel list ID and password? Many things that the Excel list is not updated even if the password is changed. Therefore, use scraping to confirm the login.

I thought it would be easy, but I got stuck a little, so I'll make a note of it.

Conclusion

Do not log in directly from the login screen. Go to the login screen from another page in Yahoo and log in.

For example Without transitioning to the login screen directly https://business.yahoo.co.jp/ ↓ https://login.bizmanager.yahoo.co.jp/login Transition in the order of.

Looking at the source of the Yahoo! Business login screen, there are many hidden items. It seems that if this .crumb is empty, you cannot log in (nothing happens). So even if you enter the correct ID and password with the hidden .crub empty, nothing happens, and even if you enter the wrong ID and password, the "ID and password are incorrect" screen is not displayed. ..

Yahoo business login screen hidden.crumb has no value


<form method="post" action="/login.php" autocomplete="off" name="login_form" onsubmit="return checkMultipleSubmit();">
<input type="hidden" name="url" value="https://business.yahoo.co.jp/" data-rapid_p="1">
<input type="hidden" name="action" value="login" data-rapid_p="2">
<input type="hidden" name=".flow" value="" data-rapid_p="3">
<input type="hidden" name=".crumb" value="" data-rapid_p="4">

https://business.yahoo.co.jp/ ↓ https://login.bizmanager.yahoo.co.jp/login When transitioning in the order of A value has been entered in the hidden .crub.

Yahoo business hidden.After the session value is set in crumb


<form method="post" action="/login.php" autocomplete="off" name="login_form" onsubmit="return checkMultipleSubmit();">
<input type="hidden" name="url" value="https://business.yahoo.co.jp/" data-rapid_p="1">
<input type="hidden" name="action" value="login" data-rapid_p="2">
<input type="hidden" name=".flow" value="" data-rapid_p="3">
<input type="hidden" name=".crumb" value="dD14Q0R0ZkImc2s9eGlqMXh3dTRLcVJzM29KQ3pLMlIwaHNVcVZvLQ==" data-rapid_p="4">

If you log in after this state, you will be able to log in by scraping.

environment Windows10 Python3.8.3 Selenium Google chrome

-It is assumed that the chrome driver is set in the driver. ・ Time.sleep is included because it may be blocked if you proceed too fast.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#Do not go directly to the login screen
driver.get("https://business.yahoo.co.jp/")
driver.get("https://login.bizmanager.yahoo.co.jp/login.php")    

#I created a function to make sure sendkey.
move_textbox_id(driver,"user_name","ID here")        
move_textbox_id(driver,"password","Password here")      
        
#I don't want to go too fast and be blocked, so go slowly.
time.sleep(1)     
    
element = driver.find_element_by_xpath("//*@id='bidlogin']/div/div/form/fieldset/div[3]/input")
element.click()

try:
  #If you can find the link text for logout, you can log in.
   WebDriverWait(driver,8).until(EC.presence_of_element_located((By.LINK_TEXT, "Logout")))
except:
  #What to do if you can't find the logout link for some reason

def move_textbox_id(driver, id, atai):
    start = time.time()
    while driver.find_element_by_id(id).get_attribute('value')!=atai:

        driver.find_element_by_id(id).clear()
        time.sleep(1)
        
        #Enter a value with the send key
        driver.find_element_by_id(id).send_keys(atai)
        time.sleep(1)

        if time.time()-start > 5 :
            return False   
    return True

It was hard to think that it was easy because I just logged in. Especially when operating in secret mode, if you log in directly from the login screen, you will never be able to log in. Certainly, the first login was rejected even when logging in manually instead of scraping. I wasn't worried because I thought I was messing around with copy and paste.

Recommended Posts

Log in to Yahoo Business with Selenium Python
Scraping with selenium in Python
Scraping with Selenium in Python
I was addicted to scraping with Selenium (+ Python) in 2020
Scraping with Selenium in Python (Basic)
How to log in to AtCoder with Python and submit automatically
Try logging in to qiita with Python
Output Python log to console with GAE
How to work with BigQuery in Python
Log in to Slack using requests in Python
To work with timestamp stations in Python
I tried to log in to twitter automatically with selenium (RPA, scraping)
Log in to the remote server with SSH
Easily log in to AWS with multiple accounts
ScreenShot with Selenium (Python)
How to use tkinter with python in pyenv
Scraping with Selenium [Python]
How to convert / restore a string with [] in python
How to do hash calculation with salt in Python
Explain in detail how to make sounds with python
How to run tests in bulk with Python unittest
Super Primer to python-Getting started with python3.5 in 3 minutes
I want to work with a robot in python.
Output log in JSON format with Python standard logging
How to download files from Selenium in Python in Chrome
How to switch to smartphone mode with Python + Selenium + Chrome
Connect to BigQuery with Python
To flush stdout in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
Login to website in Python
Connect to Wikipedia with Python
Post to slack with Python 3
Python: Working with Firefox with selenium
Start to Selenium using python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Speech to speech in python [text to speech]
Switch python to 2.7 with alternatives
Write to csv with Python
Scraping with Selenium + Python Part 2
How to develop in Python
Post to Slack in Python
Log in by passing the login session cookie obtained by Python requests to the Selenium browser.
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
[Road to intermediate Python] Install packages in bulk with pip
How to extract any appointment in Google Calendar with Python
How to manipulate the DOM in an iframe with Selenium
How to scrape at speed per second with Python Selenium
I can't log in to the admin page with Django3
[Selenium] Change log output destination when executing phantomjs in python3
Things to keep in mind when using Python with AtCoder
Things to keep in mind when using cgi with python.
Number recognition in images with Python
[Python] How to do PCA in Python
Python: How to use async with
Make apache log csv with python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import