Python 板


LINE

各位大大好: 小弟最近在練習用selenium進行網路爬蟲,正好以Agoda網站為目標爬取台北市所有的 飯店名稱(先爬取第一頁為主,然後換頁),結果顯示的結果不但沒有換頁,而且飯店名稱 只有印出四間。 以下是我的程式碼與報錯資訊,麻煩各位幫我瞧瞧哪裡寫錯了,謝謝。 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import re import time from bs4 import BeautifulSoup browser = webdriver.Chrome() browser.get('https://www.agoda.com/zh-tw/pages/agoda/default/DestinationSearchResult.aspx?asq=Ss5PXyh1QUNdFOc4lzIDoPF%2BRvl%2F2EATmGvZScKd0zV2eryqVzxofG%2BmP16PwMJIhn6ZcBnwwPWMfnG%2FN94g7S8wUgfCFrPYXSVII0eHKcYuF%2FAeuf3Ntuv%2F3UlVEtcg%2Fh%2Fe4idk67OoEy6KdHwUNum%2B3QacrQMDUE7JkJAfzu3W62o9bPbdQ8KZcSPiCaH9nxv16MZrgiZOZki0W6H9dQ%3D%3D&city=4951&cid=-999&tick=636413477452&isdym=true&searchterm=%E5%8F%B0%E5%8C%97&txtuuid=f685547f-5b5a-4507-bace-845d3ca9b6f0&pagetypeid=1&origin=TW&tag=&gclid=&aid=130243&userId=6 5319270-7a97-4746-8d25-e53b463a0ddf&languageId=20&sessionId=vlmk2yavkgwagnc4g2g12nii&storefrontId=3&currencyCode=TWD&htmlLanguage=zh-tw&trafficType=User&machineName=HK-AGWEB-2E07&cultureInfoName=zh-TW&textToSearch=%E5%8F%B0%E5%8C%97&guid=f685547f-5b5a-4507-bace-845d3ca9b6f0&checkIn=2017-09-27&checkOut=2017-09-28&los=1&rooms=1&adults=2&children=0&childages=&ckuid=65319270-7a97-4746-8d25-e53b463a0ddf&sort=agodaRecommended') soup = BeautifulSoup(browser.page_source) for ele in soup.select('.hotel-name span'): print(ele.text) browser.find_element_by_id("paginationNext").click() =========================================================================== 藝宿商旅 - 板橋館 (Yi Su Hotel) 國聯大飯店 (United Hotel) 漾館時尚溫泉旅館 (Aquabella Hotel) 馥蘭朵烏來渡假酒店 (Volando Urai Spring Spa & Resort) --------------------------------------------------------------------------- WebDriverException Traceback (most recent call last) <ipython-input-1-ded7f6ded6ba> in <module>() 11 for ele in soup.select('.hotel-name span'): 12 print(ele.text) ---> 13 browser.find_element_by_id("paginationNext").click() C:\Users\Mark Chen\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in click(self) 76 def click(self): 77 """Clicks the element.""" ---> 78 self._execute(Command.CLICK_ELEMENT) 79 80 def submit(self): C:\Users\Mark Chen\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in _execute(self, command, params) 497 params = {} 498 params['id'] = self._id --> 499 return self._parent.execute(command, params) 500 501 def find_element(self, by=By.ID, value=None): C:\Users\Mark Chen\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 295 response = self.command_executor.execute(driver_command, params) 296 if response: --> 297 self.error_handler.check_response(response) 298 response['value'] = self._unwrap_value( 299 response.get('value', None)) C:\Users\Mark Chen\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 192 elif exception_class == UnexpectedAlertPresentException and 'alert' in value: 193 raise exception_class(message, screen, stacktrace, value['alert'].get('text')) --> 194 raise exception_class(message, screen, stacktrace) 195 196 def _value_or_default(self, obj, key, default): WebDriverException: Message: unknown error: Element <button id="paginationNext" class="btn btn-right" data-selenium="pagination-next-btn">...</button> is not clickable at point (928, 554). Other element would receive the click: <span class="price soft-red" data-selenium="display-price" data-currency="">...</span> (Session info: chrome=60.0.3112.113) (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.3.9600 x86_64) --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.121.52
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1505752057.A.3E9.html
1F:→ billy0131: error msg不是有寫button is not clickable at point.. 09/19 01:15
2F:→ ebenezer: 我用GOOGLE CHROME的開發者工具去定位元素確實是顯示 09/19 03:18
3F:→ ebenezer: 下一頁的元素為id='paginationNext',不曉得為什麼無法 09/19 03:20
4F:→ ebenezer: 點擊,試了很多次了,也有試過wait的方法,但就是無法~ 09/19 03:22
5F:→ s860134: 點擊的方法有很多種,你可以嘗試 element.click 外的 09/19 03:56
6F:→ s860134: 我記得 action chain 的 click 還是 js 的可以解 09/19 03:56
7F:→ s860134: 他的意思是指元件疊在一起會先點到別人吧?(我的理解) 09/19 03:57
8F:推 amarco: try: WebDriverWait(browser, 10).until(EC.element_to_be 09/19 06:13
9F:→ amarco: _clickable((By.ID, "paginationNext"))) 09/19 06:13







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:BabyMother站內搜尋

TOP