私はPythonが初めてです。Selenium Webdriverをパラメータに渡します。 Pythonで可能ですか?
私のスクリプトの目的は、Selenium WebdriverでWebページを解析することです。 2つのサブタスクがあります。私がエラーなしで作った最初の仕事。しかし、すべてのスクリプトは機能していませんでした。
もう少し複雑な方法で2番目の課題を解決しようとしています。私は関数を使いたい。
質問です:
私は関数パラメータで活躍セレンwebdriverをを渡してもらえますか?
2番目の質問は次のとおりです。
答えがYESである場合 - 第二の機能はまた別の関数にアクティブwebdriverをを渡すだろうか?
私はWebdriverをアクティブにしてセッションを閉じることなく機能に渡すことを考えています。
私のコードは次のとおりです。
for key, value in enumerate(headers):
webdriver.DesiredCapabilities.PHANTOMJS[
'phantomjs.page.customHeaders.{}'.format(key)] = value
w = webdriver.PhantomJS()
ps = q_yn('Perform new links parsing?', default='no')
if ps:
csv_l = get_clist(w)
<...>
def get_clist(w):
w.get(url)
wait_pageload(w, 0)
src = w.page_source
BeautifulSoup(src, "lxml")
... (etc)
<..>
def wait_pageload(w, pt):
if pt == 0:
element = WebDriverWait(w, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "serg_search_result")))
elif pt == 1:
element = WebDriverWait(w, 10).until(
EC.presence_of_element_located((By.ID, "ya_share")))
else:
raise ValueError("Page type: %s is unknown" % pt)
私はこのスクリプトをビルドして実行しようとすると、私はエラーが表示されます。
File "fts-crawl2.py", line 108, in wait_pageload
EC.presence_of_element_located((By.CLASS_NAME, "serg_s")))
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/support/
wait.py", line 71, in until
value = method(self._driver)
selenium.common.exceptions.WebDriverException: Message: Error - Unable
to load Atom 'find_element' from file ':/ghostdriver/./third_party/webdriver-
atoms/find_element.js'
ありがとうございました、@RemcoW。それですべてがうまくいくはずです。例外は、Ubuntu 16.04のエラーのPhantomJSからです(このStackOverflowの質問で)。(http://stackoverflow.com/questions/36770303/phantomjs-with-selenium-unable-to-load-atom-find-element) –