武汉大学图书馆登录

发表于

# 武汉大学图书馆 2018年4月2日09:32:43 lmy整合
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time,os
from bs4 import BeautifulSoup
import warnings
#ignore UserWarning
warnings.filterwarnings("ignore")

#init brower
#b = webdriver.Chrome()
b = webdriver.PhantomJS()

#define unique string
us = time.time()

def login(bor_id='2017XXZX',bor_verification='2015XXZX'):
    b.get('http://metalib.lib.whu.edu.cn/pds?func=load-login&calling_system=aleph&url=http://opac.lib.whu.edu.cn/F/JVVV35NN2E3SL2PRXT71PTUY6QNFNITBALP9HGJITJSG6PQFA7-11626-' + str(us) + '?func=bor-info')
    #b.get_screenshot_as_file('login.png')

    p1 = b.find_element_by_name('bor_id')
    p1.send_keys(bor_id)
    p2 = b.find_element_by_name('bor_verification')
    p2.send_keys(bor_verification)
    p2.send_keys(Keys.ENTER)

    #print(b.page_source)
    #print(b.current_url)
    b.get(b.current_url)

    soup = BeautifulSoup(b.page_source, 'html5lib')
    #items = soup.select['td .td1']
    #print(soup.select('td .td1')[0].get_text())

    # print(soup.select('td .td1'))
    res = soup.select('td .td1')
    # print(res)
    try:
        name = res[0].get_text().strip()
        username = res[1].get_text().strip()
    except:
        name = ''
        username = ''

    return str(name)+'-'+str(username)

print(login())
#b.close()

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注