2014-09-24 2 views
1

그래서 웹 사이트에서 파일을 다운로드하기 위해 Selenium을 사용하고 있습니다. 35 초 동안 wait 명령을 내 렸습니다. 어디에 배치됩니다 어디에 모든 파일이 올바른지 보여하지만 내 프로그램에서 매개 변수로 파일의 이름을 전달하고 난 항상 마지막에 .part 얻을 심지어 tho 파일을 완전히 다운로드 한 내 다운로드 폴더에 제대로 표시됩니다. 여기에 내 코드 여기.partevert를 얻는 중 python으로 Selenium webdriver를 사용하여 파일을 다운로드하십시오.

Binary= FirefoxBinary('/home/what/Desktop/firefox/firefox-bin') 
profile = webdriver.FirefoxProfile() 
profile.set_preference("browser.download.folderList", 2) 
profile.set_preference("browser.download.manager.showWhenStarting", False) 
profile.set_preference("browser.download.dir", '/home/jerad/Desktop/Build') 
profile.set_preference("browser.helperApps.neverAsk.openFile", "application/octet- 
stream") 
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip") 

driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=Binary) 
driver.get("website") 
driver.find_element_by_xpath("//a[contains(text(), 'DEVcrt.sp1')]").click() 

working = "/home/what/Desktop/Build" 
abspath = os.path.join(os.getcwd(), working) 
for file1 in os.listdir(abspath): 
    abspath = os.path.join(working, file1) 
    os.path.isfile(abspath) 
time.sleep(35) 
print "fnshed downloading" 
return abspath 

j = GetUpdate() 
u = jerad.Update() 

답변

1

파이어 폭스가 .part 파일을 제거하고 끝 부분에있는 폴더에 완전히 다운로드 한 파일을 잎 (의 일부)를 호출하는 클래스입니다 성공적인 다운로드의 귀하의 코드에 문제가 있다고 생각 sleep() 후 파일에 대한 디렉토리를 스캔합니다.

은 다음과 같이 코드를 정리하십시오 :

... 

time.sleep(35) 
print "fnshed downloading" 
for file1 in os.listdir(abspath): 
    abspath = os.path.join(working, file1) 
    if os.path.isfile(abspath): 
     break 
return abspath 

을 다른 방법으로, 파이썬 여론 조사마다 초를 디렉토리를 가지고 즉시 반환 할 수는 비 .part 파일 발견과 같이

... 
max_polls = 35 
polls = 0 

while polls < max_polls: 
    for file1 in os.listdir(abspath): 
     if not file1.endswith('.part') and os.path.isfile(file1): 
      print 'finished downloading' 
      return os.path.join(working, file1) 
    time.sleep(1) 
    polls += 1 

을 다운로드가 끝나자 마자 10 초 밖에 걸리지 않는 것처럼 들립니다.

관련 문제