2016-04-25 14 views
-1

Ich versuche, ein Programm in Python 3.5 mit Selenium zu schreiben, um den Download-Prozess in zbigz.com mit Firefox Webdriver zu automatisieren. Mein Code ist wie folgt:Zugriff auf Elemente auf der nächsten Seite in Selen Python

import time 
from selenium import webdriver 
from selenium.common.exceptions import TimeoutException 

#magnet link for the purpose of testing 
mag = "magnet:?xt=urn:btih:86259d1c8d9dfbe15b6290268231e68d414fed23&dn=The.Big.Bang.Theory.S09E21.HDTV.x264-LOL%5Bettv%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969" 

def startdriver(): 
    #starting firefox driver and waiting for 100 seconds 
    driver = webdriver.Firefox() 
    driver.implicitly_wait(100) 
    return driver 

def download(driver, url, mg): 
    #opening up firefox at url = www.zbigz.com 
    driver.get(url) 

    try: 
     #accessing the required elements on the first page that opens up 
     entry_box = driver.find_element_by_xpath('.//*[@id=\'text-link-input\']') 
     go_button = driver.find_element_by_id('go-btn') 

     #entering magnet link 
     entry_box.clear() 
     entry_box.send_keys(mg) 
     #clicking on the 'Go' button 
     go_button.click() 

     #accessing the free option 
     free_button = driver.find_element_by_id('cloud-free-btn') 
     #clicking on the free option 
     free_button.click() 

     #now comes the next page ('www.zbigz.com/myfiles') where everything goes wrong 
     while driver.find_elements_by_tag_name('html') is None: #waiting for the page to load 
      continue 

     #this button is what I need to click 
     cloud_btn = driver.find_elements_by_xpath('.//*[@id=\'86259d1c8d9dfbe15b6290268231e68d414fed23\']/div[1]') 
     #allowing some time so that the download gets cached fully 
     time.sleep(60) 
     #clicking 
     cloud_btn.click() 

    except TimeoutException: 
     print('Page could not be loaded. Get a better connection!') 

if __name__=='__main__': 
    #starting driver and downloading 
    d = startdriver() 
    download(d, zbigz, mag) 
    time.sleep(30) 
    d.quit() 

Allerdings kann ich nicht auf die Schaltfläche auf der nächsten Seite zugreifen. Wenn ich diesen Code ausführen ist dies der Fehler, den ich bekommen:

Traceback (most recent call last): File "G:/Python/PyCharm Projects/TorrentDownloader.py", line 88, in download(d, zbigz, mag) File "G:/Python/PyCharm Projects/TorrentDownloader.py", line 80, in download cloud_btn.click() AttributeError: 'list' object has no attribute 'click'

Ich glaube, dass ich nicht in der Lage bin Elemente auf teh nächste Seite zuzugreifen. Und da die Methode für die Übermittlung POST ist, kann ich driver.get(zbigz+'myfiles') nicht verwenden.

Bitte schlagen Sie eine Möglichkeit vor, auf die Elemente auf der folgenden Seite zuzugreifen.

Antwort

Verwandte Themen