欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)自動(dòng)登錄

 更新時(shí)間:2018年09月17日 09:42:46   作者:語暖心扉  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)自動(dòng)登錄,填充網(wǎng)頁表單,從而自動(dòng)登錄WEB門戶,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

利用python,可以實(shí)現(xiàn)填充網(wǎng)頁表單,從而自動(dòng)登錄WEB門戶。

(注意:以下內(nèi)容只針對(duì)python3)

環(huán)境準(zhǔn)備:

(1)安裝python
(2)安裝splinter,下載源碼 python setup install

#coding=utf-8
import time
from splinter import Browser
 
def login_mail(url):
  browser = Browser()
  #login 163 email websize
  browser.visit(url)
  #wait web element loading
  #fill in account and password
  browser.find_by_id('username').fill('你的用戶名稱')
  browser.find_by_id('password').fill('你的密碼')
  #click the button of login
  browser.find_by_id('loginBtn').click()
  time.sleep(5)
  #close the window of brower
  browser.quit()
 
if __name__ == '__main__':
  mail_addr ='http://reg.163.com/'
  login_mail(mail_addr)

Tips:

(1)如果需要修改web的html屬性,可以使用:js

browser.execute_script('document.getElementById("Html屬性ID").value = "在此提供默認(rèn)值"')

(2)browser = Browser()

不指定的情況下,瀏覽器驅(qū)動(dòng)是火狐(Firefox),可以指定其他:browser = Browser(‘chrome'),需要下載對(duì)應(yīng)的驅(qū)動(dòng)程序

1.python3瀏覽頁面

#coding=utf-8
import urllib.request
import time
#在請(qǐng)求加上頭信息,偽裝成瀏覽器訪問
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
chaper_url='http://XXX'
 
vist_num=1
while vist_num<1000:
 if vist_num%50==0:
  time.sleep(5)
 print("This is the 【 "+str(vist_num)+" 】次嘗試")
 req = urllib.request.Request(url=chaper_url, headers=headers) 
 urllib.request.urlopen(req).read() #.decode('utf-8')
 vist_num+=1

2.python 多線程

#coding=utf-8
import threading #導(dǎo)入threading包
from time import sleep
import time
 
def fun1(): 
  print ("Task 1 executed." )
  time.sleep(3)
  print ("Task 1 end." )
 
def fun2():
  print ("Task 2 executed." )
  time.sleep(5)
  print ("Task 2 end." )
  
threads = [] 
t1 = threading.Thread(target=fun1) 
threads.append(t1)
t2 = threading.Thread(target=fun2)
threads.append(t2)
 
for t in threads:
  # t.setDaemon(True) 
  t.start() 

3.利用python下載百度圖片

#coding=utf-8
import urllib.request
import re
 
def getHtml(url):
  page = urllib.request.urlopen(url)
  html = page.read()
  return html
 
def getImg(html):
  reg = r'src="(.+?\.jpg)"'
  imgre = re.compile(reg)
  html=html.decode('utf-8')
  imglist = re.findall(imgre,html)
  x = 0
  for imgurl in imglist:
    urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
    x+=1
    print(str(x))

html = getHtml("http://image.baidu.com/channel?c=%E6%91%84%E5%BD%B1&t=%E5%85%A8%E9%83%A8&s=0")
 
print(getImg(html))

效果:

官網(wǎng):鏈接地址

官方示例程序:鏈接地址

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python編程中字符串和列表的基本知識(shí)講解

    Python編程中字符串和列表的基本知識(shí)講解

    這篇文章主要介紹了Python編程中字符串和列表的基本知識(shí)講解,是Python入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-10-10
  • 原生python實(shí)現(xiàn)knn分類算法

    原生python實(shí)現(xiàn)knn分類算法

    這篇文章主要介紹了原生python實(shí)現(xiàn)knn分類算法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Pytorch中torch.utils.checkpoint()及用法詳解

    Pytorch中torch.utils.checkpoint()及用法詳解

    在PyTorch中,torch.utils.checkpoint?模塊提供了實(shí)現(xiàn)梯度檢查點(diǎn)(也稱為checkpointing)的功能,這篇文章給大家介紹了Pytorch中torch.utils.checkpoint()的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2024-03-03
  • 11月編程語言排行榜 Python逆襲C#上升到第4

    11月編程語言排行榜 Python逆襲C#上升到第4

    11月編程語言排行榜 Python逆襲C#上升到第4,無論在哪個(gè)榜單中 Python 都是保持著非同尋常的增長速度,為什么Python增長的這么快
    2017-11-11
  • python自動(dòng)化unittest yaml使用過程解析

    python自動(dòng)化unittest yaml使用過程解析

    這篇文章主要介紹了python自動(dòng)化unittest yaml使用過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • 使用Python NumPy庫繪制漸變圖案

    使用Python NumPy庫繪制漸變圖案

    NumPy(Numerical Python)是Python的一種開源的數(shù)值計(jì)算擴(kuò)展。這種工具可用來存儲(chǔ)和處理大型矩陣。但其實(shí)NumPy還可以繪制圖畫,本文將為大家介紹如何通過NumPy繪制彩色圖畫,感興趣的小伙伴可以了解一下
    2021-12-12
  • Python必考的5道面試題集合

    Python必考的5道面試題集合

    這篇文章介紹了Python必考的5道面試題,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • Python作用域(局部?全局)及global關(guān)鍵字使用詳解

    Python作用域(局部?全局)及global關(guān)鍵字使用詳解

    這篇文章主要為大家介紹了Python作用域(局部?全局)及global關(guān)鍵字使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • Python包管理工具pip用法詳解

    Python包管理工具pip用法詳解

    本文詳細(xì)講解了Python包管理工具pip的用法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • python中PS 圖像調(diào)整算法原理之亮度調(diào)整

    python中PS 圖像調(diào)整算法原理之亮度調(diào)整

    這篇文章主要介紹了python中PS 圖像調(diào)整算法原理之亮度調(diào)整,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06

最新評(píng)論