2015-11-01 61 views
-2

是沒有必要的進口的Python /硒幾個問題

results = [] 
with open("al.txt") as inputfile: 
    for line in inputfile: 
     results.extend(line.strip().split(',')) 

x = random.choice(results) 
chromedriver = "C:\Python27\Scripts\chromedriver" 
os.environ["webdriver.chrome.driver"] = chromedriver 


driver = webdriver.Chrome(chromedriver) 
driver.get(x) 
time.sleep(10) 
x = driver.find_element_by_xpath("/html/body/div[2]/div/div/table[1]/tbody/tr/td[2]/form/table/tbody/tr[1]/td[2]/input") 
b = driver.find_element_by_xpath("/html/body/div[2]/div/div/table[1]/tbody/tr/td[2]/form/table/tbody/tr[2]/td[2]/input") 
c = driver.find_element_by_xpath("/html/body/div/div/div/table[1]/tbody/tr/td[2]/form/table/tbody/tr[2]/td[3]/input") 
time.sleep(1) 
x.send_keys("x") 
time.sleep(1) 
b.send_keys("y") 
time.sleep(1) 
c.click() 
time.sleep(5) 
element = driver.find_element_by_id("vB_Editor_QR_textarea") 
post = driver.find_element_by_xpath("/html/body/div[3]/div/div/form/table/tbody[2]/tr/td/div[2]/input[10]") 
time.sleep(2) 
element.send_keys("dsada") 
time.sleep(1) 
post.click() 
time.sleep(30) 

所以,第一個問題是我的代碼:我嘗試做了這樣的循環,但每當我嘗試添加「而真正的」該代碼被打破,使縮進錯誤

的第二個問題是:司機等待太多的負荷,我希望它跳過裝載部分和完成的任務時,它可識別元素

我會真的如果任何人都可以回答這些問題,那麼他們就會受到歡迎

回答

0

第一個問題 - 這是python的基礎知識。如何在不知道基礎知識的情況下寫出一些複雜的東西?只要看看任何python教程的第一頁。任何建築,你的情況 - while循環可以看到的代碼塊,屬於,只有當它與縮進做(至少2位):

# Wrong: 
i = 0 
while i < 5: 
print i 
i += 1 

# Correct: 
i = 0 
while i < 5: 
    print i 
    i += 1 

的第二個問題 - 看wait.until,但在學習了python的基本知識之後:)

+1

提到「python基礎知識」並不是一個答案,更好的還是一個評論。 –

+0

可能,是的。我會編輯我的答案。 – Sergius

+0

我試過我的代碼,使用4個空格的同時使用循環,這就是它讓我困惑的原因它仍然給縮進錯誤 –