【Python】數字驅動

來源:互聯網
上載者:User

標籤:檔案   pen   main   sele   driver   selenium   pytho   open   ali   

#練習1:開啟3個網址,每個等3秒鐘

urls.txt:

http://www.baidu.com
http://www.sogou.com
http://www.sohu.com

main.py:
from selenium import webdriver
import time

driver = webdriver.Chrome(executable_path = "c:\\chromedriver")
with open("urls.txt") as fp: #urls.txt裡存三個網址
for url in fp:
driver.get(url)
time.sleep(3)
driver.current_url
driver.quit()

 1 #練習2:通過命令列選擇瀏覽器或檔案開啟和執行 2 urls.txt: 3 http://www.baidu.com 4 http://www.sogou.com 5 http://www.sohu.com 6  7 main.py: 8 #python test.py chrome  http://www.sohu.com 9 #python test.py ie  urls.txt10 11 from selenium import webdriver12 import sys13 import time14 15 if len(sys.argv)!=3:16     print "parameter number is not valid!"17     sys.exit()18 19 browser_type=sys.argv[1]20 file_or_url=sys.argv[2]21 22 if browser_type.lower()=="chrome":23     driver = webdriver.Chrome(executable_path = "c:\\chromedriver")24 elif browser_type.lower()=="ie":25     driver = webdriver.Ie(executable_path = "c:\\IEDriverServer")26 else:27     driver = webdriver.Firefox(executable_path = "c:\\geckodriver")28 29 if file_or_url.find("http://")!=-1:30     driver.get(file_or_url)31 else:32     with open(path) as fp: #urls.txt裡存三個網址33         for url in fp:34             driver.get(url)35             time.sleep(3)36             driver.current_url37 driver.quit() 

 

【Python】數字驅動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.