Я не могу войти в Yahoo, используя Python 3 в Microsoft Edge
Вот мой код:
import logging
import time
from bs4 import BeautifulSoup # import bs
import requests # import request
from selenium import webdriver
# set directory
import os.path
_dir = os.path.dirname(os.path.abspath("c:\temp"))
# create session
def create_session():
s = requests.Session()
s.headers.update({
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "ja,en-US;q=0.7,en;q=0.3",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0"
})
return s
# main routine
def yahoojp_session(target_url, login_id, password):
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "ja,en-US;q=0.7,en;q=0.3",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0"
}
# call webdriver
cap = webdriver.DesiredCapabilities.PHANTOMJS
for key, val in headers.items():
cap["phantomjs.page.customHeaders." + key] = val
cap["phantomjs.page.settings.userAgent"] = headers["User-Agent"]
# call webdriver
try:
# <class 'selenium.webdriver.phantomjs.webdriver.WebDriver'>
driver = webdriver.Edge(executable_path='C:\\temp\\MicrosoftWebDriver.exe')
except Exception as e:
logging.error(e)
return None
# Get cookies
driver.get(target_url)
# print url
print(target_url)
bs4 = BeautifulSoup(driver.page_source, "html5lib")
login_url = bs4.find("a", attrs={"id": "msthdLogin"})["href"]
# get login url
driver.get(login_url)
time.sleep(1)
# send login id
driver.find_element_by_name("login").send_keys(login_id)
driver.find_element_by_name("btnNext").click() # next button
time.sleep(1)
# send password
driver.find_element_by_name("passwd").send_keys(password)
driver.find_element_by_name("btnSubmit").click() # login button
time.sleep(1)
driver.save_screenshot(_dir + "/login.png") # Save image
# move session
s = create_session()
for c in driver.get_cookies():
s.cookies[c["name"]] = c["value"]
# close driver
driver.close()
return s
# main
if __name__ == '__main__':
s = yahoojp_session("https://login.yahoo.co.jp/", "test1234", "test5678")
ОШИБКА: root: Сообщение: неизвестноошибка
ОШИБКА: root: Сообщение: неизвестная ошибка