2016-12-12 13 views
0

私が達成しようとしているのは、美しいスープを使ってページを解析して情報を引き出すことです。その後、Seleniumを使って次のページに移動し、この操作を繰り返します。次のページ。Selenium + Python。

Traceback (most recent call last): 
File "testpull.py", line 18, in <module> 
elm.click() 
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 72, in click 
self._execute(Command.CLICK_ELEMENT) 
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 461, in _execute 
return self._parent.execute(command, params) 
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute 
self.error_handler.check_response(response) 
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response 
raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (172, 612). Other element would receive the click: <p class="cc_message">...</p> 
(Session info: chrome=54.0.2840.99) 
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 10.0.10240 x86_64) 

私はトライなステートメントの最後のビットなしにそれを実行しようとした:ここで私は私がしようとすると、これを実行すると、私はこのエラーを取得する

while True: 
    try: 
     for content in cards.find_all('div',{'class':'el-card-visual'}): 
      print (content.find('img')['alt']) 
      print (content.find('a')['href']) 
     elm = driver.find_element_by_css_selector('span.is-next') 
     elm.click() 
     URL = driver.current_url 
     driver.get(URL) 
     HTML = driver.page_source 
     cards = BeautifulSoup(HTML,'lxml') 
    except: 
     break 

で問題が生じています関連するコードスニペットです(elm.click()の後ろのすべて)、最初のページから何度も何度もループして印刷していました。

この問題の最適な解決策は何ですか?

+0

「次へ」ボタンをクリックした後に「URL」が変わるのですか? – Andersson

答えて

0

私は自分の昨夜、もう少しコードを使いこなし、最後に少し余裕があることを発見しました。私が必要としたのは、単純に:

elm = driver.find_element_by_css_selector('span.is-next') 
elm.click() 
HTML = driver.page_source 
cards = BeautifulSoup(HTML,'lxml') 

その他でした。