参考地址:https://www.cnblogs.com/lingwang3/p/7750156.html
# 获取cookie
import time
from selenium import webdriver driver = webdriver.Chrome()
driver.delete_all_cookies()
login_url = 'https://sso.accounts.dowjones.com/login?client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&redirect_uri=https%3A%2F%2Faccounts.wsj.com%2Fauth%2Fsso%2Flogin&scope=openid%20idp_id%20roles%20email%20given_name%20family_name%20djid%20djUsername%20djStatus%20trackid&response_type=code&nonce=02a76f8f-7b75-4095-82c4-ec8af2ae7e1a&connection=DJldap&ui_locales=en-us-x-wsj-19-2&mg=prod%2Faccounts-wsj&state=0k67vXdeRlXvGO2UEftM5cB0f-4Nt458#!/signin'
driver.get(login_url)
user = driver.find_element_by_css_selector('input[name="username"]')
user.send_keys('[email protected]')
pwd = driver.find_element_by_css_selector('input[name="password"]')
time.sleep()
pwd.send_keys('wise123')
time.sleep()
driver.find_element_by_css_selector('button[class="solid-button basic-login-submit"]').click()
time.sleep()
driver.switch_to_default_content()
time.sleep()
list_cookies = driver.get_cookies()
for t in list_cookies:
if t['name'] == 'djcs_session':
djcs_session = t['value']
break
else:
djcs_session = False if djcs_session:
header = {
"cookie": "djcs_session=%s" % djcs_session
}
else:
exit("cookie get faild..")
print(header)