1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| # -*- coding: UTF-8 -*- from selenium import webdriver import time,os,re,sys from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.action_chains import ActionChains from sheen import Str from selenium.webdriver.common.keys import Keys
chromedriver=r"C:\Program Files\Google\Chrome\Application\chromedriver.exe" #针对编码格式的操作 options = webdriver.ChromeOptions() options.add_argument("lang=zh_CN.UTF-8") #options.add_argument('--headless') #声明浏览器 browser = webdriver.Chrome(chromedriver,options=options) url = r"https://dns.he.net/"
#username="365dl1" #password=r"helloworld"
def main(): while True: xuanzhe=input("选择添加dns网站,1 为dns.he.net, 2 为退出:\n") if xuanzhe == "1": addDns() elif xuanzhe == "2": print("退出") sys.exit() else: print("退出") sys.exit() break
def addDns(): # get打开指定的url,传入要打开的url, browser.get(url) # 通过find_element_by_name获取到网页标签,send_keys()输入内容,在搜索栏输入python username = input("请输入dns.he.net的账号名: \n") password = input("请输入%s账号的密码\n" %(username)) cname = input("请输入cname地址 如: site.365ok365ok.com\n") browser.find_element_by_name("email").send_keys(username) browser.find_element_by_name("pass").send_keys(password) #登录 browser.find_element_by_xpath("//*[@id='_loginbutton']").click() time.sleep(3) #点击free dns browser.find_element_by_xpath("//*[@id='navigation']/div[3]/div[2]/a[3]").click() time.sleep(1)
#domain = with open("domian.txt" , "r" , encoding="utf-8") as f: # print(f.read()) path = "domian.txt" n = int(input("现在是该账号的第几条域名,第二条请输入 2\n"))
with open(path, "r") as f: while True:
lineInfo = f.readline() if len(lineInfo) < 3: break
#新增域名 browser.find_element_by_xpath("//*[@id='navigation']/div[2]/ul/li[1]/a").click() #点击域名框 time.sleep(2) #browser.find_element_by_xpath("// *[ @ id = '_name']").click() #输入域名 browser.find_element_by_xpath("// *[ @ id = '_name']").send_keys(lineInfo) #不定位元素直接回车 ActionChains(browser).send_keys(Keys.ENTER).perform() #browser.find_element_by_xpath("// *[ @ id = '_name']").send_keys(Keys.ENTER)
time.sleep(5)
#input("请按回车提交域名:") # print("第一次添加域名一般不用手动点击提交域名按钮,后面有时候有需要提交") # shou = input("是否手动提交域名y是n为不是,输入其他表示域名有误不能添加,请联系服务商。\n") # if shou == "y": # #提交域名 # browser.find_element_by_xpath("//*[@id='add_zone']/form/input[3]").click() # elif shou == "n": # pass # else: # print("域名有误, 退出程序") # sys.exit() time.sleep(5)
#进入新增域名编辑页面
time.sleep(2) list_xpath = "//*[@id='domains_table']/tbody/tr[{}]/td[2]".format(n) browser.find_element_by_xpath(list_xpath).click() print("已添加域名 ", lineInfo) #browser.find_element_by_name(lineInfo).click() time.sleep(2) #新增alias别名信息 browser.find_element_by_xpath("//*[@id='jsddm']/li[4]/a").click() time.sleep(1) #点击name browser.find_element_by_xpath("//*[@id='_name' and @name='Name']").click() #输入 browser.find_element_by_xpath("//*[@id='_name' and @name='Name']").send_keys("@") #点击Hostname browser.find_element_by_xpath("//*[@id='_content' and @name='Content']").click() browser.find_element_by_xpath("//*[@id='_content' and @name='Content']").send_keys("www." + lineInfo) #提交 ActionChains(browser).send_keys(Keys.ENTER).perform() #browser.find_element_by_xpath("//*[@id='_content' and @name='Content']").send_keys(Keys.ENTER) # if shou == "y": # # browser.find_element_by_xpath("//*[@id='_hds']").click() # else: # pass time.sleep(2)
browser.find_element_by_xpath("//*[@id='jsddm']/li[3]/a").click() time.sleep(1)
#点击后输入www browser.find_element_by_xpath("//*[@id='_name']").click() browser.find_element_by_xpath("//*[@id='_name']").send_keys("www")
browser.find_element_by_xpath("//*[@id='_content']").click() browser.find_element_by_xpath("//*[@id='_content']").send_keys(cname) #TTL设置1小时 browser.find_element_by_xpath("//*[@id='_ttl']").click() browser.find_element_by_xpath("// *[ @ id = '_ttl']/option[7]").click() #提交 time.sleep(1)
browser.find_element_by_xpath("//*[@id='_hds']").click() time.sleep(3) print("已添加域名%s,且已解析 " %(lineInfo))
browser.find_element_by_xpath("//*[@id='navigation']/div[3]/div[2]/a[3]").click() time.sleep(3) n += 1
if __name__ == "__main__": main() #os.system("pause") time.sleep(3) browser.close() browser.quit()
|