98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
![]() |
import time
|
||
|
|
||
|
from selenium import webdriver
|
||
|
from selenium.webdriver.common.by import By
|
||
|
from selenium.webdriver.support import expected_conditions
|
||
|
from selenium.webdriver.support.wait import WebDriverWait
|
||
|
|
||
|
HOME_PAGE_URL = 'https://fuzhou.mysteel.com/'
|
||
|
USERNSAME = '13960925044'
|
||
|
PASSWORD = 'mysteel336627'
|
||
|
|
||
|
|
||
|
def load_element(browser, pattern, time=3600.0):
|
||
|
''' 等待元素载入 '''
|
||
|
element = WebDriverWait(browser, time).until(expected_conditions.presence_of_element_located((By.XPATH, pattern)))
|
||
|
return element
|
||
|
|
||
|
|
||
|
def login_mysteel():
|
||
|
options = webdriver.ChromeOptions()
|
||
|
browser = webdriver.Remote(
|
||
|
command_executor="http://localhost:4444/wd/hub",
|
||
|
options=options
|
||
|
)
|
||
|
|
||
|
browser.get(HOME_PAGE_URL)
|
||
|
print('Visit {0} ...'.format(HOME_PAGE_URL))
|
||
|
print(browser.title)
|
||
|
try:
|
||
|
# 打开登陆窗口
|
||
|
print('Click Login...')
|
||
|
time.sleep(1)
|
||
|
load_element(browser, '//*[@id="mysteel-topBar"]/div[3]/p').click()
|
||
|
time.sleep(1)
|
||
|
|
||
|
# 填写登陆资料
|
||
|
print('Insert data ...')
|
||
|
print('username: {0}'.format(USERNSAME))
|
||
|
browser.find_elements(By.XPATH, "//div[contains(text(),'账号登录')]")[0].click()
|
||
|
time.sleep(2)
|
||
|
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[5]/div[1]/input')[0].send_keys(USERNSAME)
|
||
|
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[5]/div[3]/input')[0].send_keys(PASSWORD)
|
||
|
time.sleep(1)
|
||
|
browser.find_elements(By.XPATH, '/html/body/div/div/div[2]/div[6]/div[1]/div[1]')[0].click()
|
||
|
time.sleep(5)
|
||
|
|
||
|
cookies = browser.get_cookies()
|
||
|
for i in range(10):
|
||
|
if cookies:
|
||
|
break
|
||
|
else:
|
||
|
browser.refresh()
|
||
|
time.sleep(5)
|
||
|
cookies = browser.get_cookies()
|
||
|
|
||
|
print(cookies)
|
||
|
print([i for i in cookies if i['name'] == '_login_token'])
|
||
|
print([i for i in cookies if i['name'] == '_MSPASS_SESSION'])
|
||
|
return cookies
|
||
|
finally:
|
||
|
browser.close()
|
||
|
browser.quit()
|
||
|
|
||
|
|
||
|
def login_baiinfo(home_page_url='http://www.baiinfo.com/shiyou/liqing', usernsame='fjglsl', password='111111'):
|
||
|
options = webdriver.ChromeOptions()
|
||
|
browser = webdriver.Remote(
|
||
|
command_executor="http://localhost:4444/wd/hub",
|
||
|
options=options
|
||
|
)
|
||
|
browser.set_window_size(1280, 800)
|
||
|
browser.get('http://www.baiinfo.com/login')
|
||
|
print('Visit {0} ...'.format(home_page_url))
|
||
|
print(browser.title)
|
||
|
try:
|
||
|
# 填写登陆资料
|
||
|
print('Insert data ...')
|
||
|
print('username: {0}'.format(usernsame))
|
||
|
load_element(browser, '//*[@id="__nuxt"]')
|
||
|
print('ddd')
|
||
|
time.sleep(2)
|
||
|
browser.find_elements(By.XPATH, '//form/div[1]/input')[0].click()
|
||
|
browser.find_elements(By.XPATH, '//form/div[1]/input')[0].send_keys(usernsame)
|
||
|
browser.find_elements(By.XPATH, '//form/div[2]/input')[0].send_keys(password)
|
||
|
time.sleep(3)
|
||
|
browser.find_elements(By.XPATH, '//*[@id="__nuxt"]/div/div[5]/div/div[2]/div/div[2]/div[2]/div[2]/form/div[4]/div/img')[0].click()
|
||
|
time.sleep(4)
|
||
|
cookies = browser.get_cookies()
|
||
|
print(cookies)
|
||
|
return cookies
|
||
|
finally:
|
||
|
browser.close()
|
||
|
browser.quit()
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
login_baiinfo()
|