自动登录12306

版权声明:转载请注明出处 https://blog.csdn.net/sixkery/article/details/82824927

简单的登录操作,等有空的话写一个自动登录的爬虫吧。

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()

猜你喜欢

转载自blog.csdn.net/sixkery/article/details/82824927