zoukankan      html  css  js  c++  java
  • python自动化之爬虫模拟登录

    http://selenium-python.readthedocs.io/locating-elements.html

    ################################################################################

    ################################################################################

    ################################################################################

    from selenium import webdriver

    import time

    driver=webdriver.PhantomJS(executable_path=r"D:phantomjs-2.1.1-windowsphantomjs-2.1.1-windowsinphantomjs.exe") #启动phantomjs,模拟登录

    driver.set_window_size(480,800) #设置浏览器宽480,高800

    driver.get('https://qzone.qq.com/') #登录QQ空间主页

    driver.switch_to.frame('login_frame') #切换到登录frame,因为frame的代码是独立的,必须切换到frame上,很多人在用selenium定位页面元素的时候会遇到定位不到的问题,明明元素就在那儿,用firebug也可以看到,就是定位不到,这种情况很有可能是frame在搞鬼

    time.sleep(10)

    #通过使用选择器选择到表单元素进行模拟输入和点击按钮提交

    driver.find_element_by_id('switcher_plogin').click()

    driver.find_element_by_id('u').clear()

    driver.find_element_by_id('u').send_keys("******") ##账号

    driver.find_element_by_id('p').clear()

    driver.find_element_by_id('p').send_keys("*******") ##密码

    driver.find_element_by_id('login_button').click()

    time.sleep(10)

    print (driver.page_source.split(r'当前空间等级:')[1].split(r';积分')[0])

    ################################################################################

    ################################################################################

    ################################################################################

    from selenium import webdriver

    import time

    driver=webdriver.PhantomJS(executable_path=r"D:phantomjs-2.1.1-windowsphantomjs-2.1.1-windowsinphantomjs.exe")

    driver.set_window_size(480,800)

    driver.get('https://mail.qq.com/cgi-bin/loginpage')

    driver.switch_to.frame('login_frame')

    time.sleep(10)

    driver.find_element_by_id('switcher_plogin').click()

    driver.find_element_by_id('u').clear()

    driver.find_element_by_id('u').send_keys("******") ##账号

    driver.find_element_by_id('p').clear()

    driver.find_element_by_id('p').send_keys("*******") ##密码

    driver.find_element_by_id('login_button').click()

    time.sleep(10)

    print (driver.page_source)

  • 相关阅读:
    小喵的在线共享编辑器
    简易漫画网站搭建-漫画喵Server版
    爬虫-漫画喵的100行逆袭
    应用OpenMP的一个简单的设计模式
    基于Caffe的Large Margin Softmax Loss的实现(中)
    基于Caffe的Large Margin Softmax Loss的实现(上)
    Oracle GoldenGate OGG管理员手册
    Spark快速大数据分析之RDD基础
    Apache Spark大数据分析入门(一)
    一文教你看懂大数据的技术生态圈:Hadoop,hive,spark
  • 原文地址:https://www.cnblogs.com/dudumiaomiao/p/8145672.html
Copyright © 2011-2022 走看看