溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

簡單的混合驅動

發布時間:2020-07-12 01:19:38 來源:網絡 閱讀:266 作者:qq5a16e6241946e 欄目:編程語言

數據文件:

testdata.txt

visit||http://www.bing.com
visit||${e:\urls.txt}

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

#encoding=utf-8
from selenium import webdriver
import re

driver = webdriver.Chrome(executable_path="d:\\chromedriver")

def visit(url):
    global driver
    driver.get(url)

def main(filepath):
    with open(filepath) as fp:
        for line in fp:
            if line.strip():
                if re.search(r"\${(.*?)}",line):
                    action = line.split("||")[0]
                    data_file = re.search(r"\${(.*?)}",line).group(1)
                    with open(data_file)  as file_obj:
                        for url in  file_obj:
                            command = "%s('%s')" %(action,url.strip())
                            eval(command)

                else:
                    action = line.split("||")[0]
                    url = line.split("||")[1].strip()
                    command = "%s('%s')" %(action,url)
                    eval(command)

if __name__ == "__main__":
    main("E:\\python\\自動化\\testdata.txt")
    driver.quit()
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女