Selenium ConnectionAbortedError

时间:2018-06-20 11:06:59

标签: python selenium

编码新手:我正在编写一个小的脚本,该脚本可在登录大学帐户后下载PDF。一切顺利进行,直到准备好PDF后单击下载按钮的最后一步,然后出现错误,连接被中止。

该错误发生在脚本的第二行,但是我无法弄清楚自己在做错什么-我需要做的就是单击新出现的下载按钮,并且我使用的是相同的网络驱动程序以前成功单击按钮的方法。

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup
import re
import os
import pyperclip

#launch url from clipboard
#url = pyperclip.paste()
url = 'https://ebookcentral.proquest.com/lib/unimelb/detail.action?docID=438856' #test URL


#create a Firefox session
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get(url)

#Login to Unimelb

userinput = driver.find_element_by_id('usernameInput')
pwinput = driver.find_element_by_id('passwordInput')

userinput.send_keys("redacted")
pwinput.send_keys("redacted")

driver.implicitly_wait(10)

loginbutton = driver.find_element_by_xpath("/html/body/div/div[2]/div[1]/section/form/div[2]/button")
loginbutton.click()

#Find PDF download buttons

pdf_1 = driver.find_element_by_id("tool_chapterdownload_438856_1_1")
pdf_1.click()

#wait a moment until PDF is ready
time.sleep(5)

#dies here
downloadbutton = driver.find_element_by_xpath('//*[@id="chapterOpenPDF"]')
downloadbutton.click()

错误:

Traceback (most recent call last):
  File "C:\Users\Laptop\Desktop\Book_Downloader.py", line 43, in <module>
    driver.find_element_by_xpath('//*[@id="chapterOpenPDF"]').click()
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 387, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 957, in find_element
    'value': value})['value']
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
    self.send(chunk)
  File "C:\Users\Laptop\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
    self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

0 个答案:

没有答案