basic programming python: python + 163 E-mail method to achieve automatic landing selenium

This article describes the

Let us for a preview of the effect of code to run it: Here Insert Picture Description
Firstly page structure 163 E-mail page (press F12 or click the right mouse button and select Inspect Element) Here Insert Picture Description
1, locate the login box (note the login box is an iframe, if you do not locate the iframe words are after can not find the email address box and password box) Here Insert Picture Description
2, navigate to the email address box (name = 'Email') Here Insert Picture Description
3, navigate to the password input box (name = 'password')
Here Insert Picture Description
4, navigate to the login button (the above mentioned id = 'doLogin') Here Insert Picture Description5, the analysis is complete, you can now write code to achieve automatic landing 163 E-mail your friends (with detailed analysis of code!)

#coding:utf-8
from selenium import webdriver
import time
def login():
  dr = webdriver.Chrome()
  #打开登陆163邮箱的网页
  dr.get('http://mail.163.com/')
 
  #将浏览器窗口最大化
  dr.maximize_window()
 
  #休息五分钟等待网页加载完毕
  time.sleep(5)
 
  #找到邮箱账号登录框对应的iframe
  dr.switch_to.frame('x-URS-iframe')
 
  #找到邮箱账号输入框
  email = dr.find_element_by_name('email')
 
  #将自己的邮箱地址输入到邮箱账号框中
  email.send_keys('chimuyhs')
 
  #找到密码输入框
  password = dr.find_element_by_name('password')
 
  #输入自己的邮箱密码
  password.send_keys('xxxxxx')
 
  #找到登陆按钮
  login_btn = dr.find_element_by_id('dologin')
 
  #点击登陆按钮
  login_btn.click()
 
  #等待10秒看是否登陆成功
  time.sleep(10)
if __name__ == '__main__':
 
  login()

Content on more than how many, and finally to recommend a good reputation in the number of public institutions [programmers], there are a lot of old-timers learning skills, learning experience, interview skills, workplace experience and other share, the more we carefully prepared the zero-based introductory information on actual project data every day to explain the timing of Python programmers technology, and share some learning methods need to pay attention to small detailsHere Insert Picture Description

Published 20 original articles · won praise 0 · Views 3606

Guess you like

Origin blog.csdn.net/chengxun02/article/details/104998987