简单的登录操作,等有空的话写一个自动登录的爬虫吧。
from lxml import etree
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import xlrd,xlwt,re,codecs,time
class QingPiao():
def __init__(self):
self.browser = webdriver.Chrome()
self.url = 'https://kyfw.12306.cn/otn/login/init'
self.wait = WebDriverWait(self.browser,50)
# 登录后个人页面的url
self.myurl = 'https://kyfw.12306.cn/otn/index/initMy12306'
def login(self):
self.browser.get(self.url)
# 如果页面跳转到个人页面,则登录成功
self.wait.until(EC.url_to_be(self.myurl))
print('登录成功')
def run(self):
self.login()
def main():
qingpiao = QingPiao()
qingpiao.run()
if __name__ == '__main__':
main()