各位大大好:
小弟最近在練習用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¤cyCode=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)