https://www.youtube.com/watch?v=tMvXBTsFYoQ&list=PL9mhQYIlKEhf0DKhE-E59fR-iu7Vfpife&index=2 ================================================================================ import time from selenium import webdriver as wd from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC ================================================================================ main_url="http://tour.interpark.com/" keyword="Rome" driver=wd.Chrome(executable_path="./chromedriver") driver.get(main_url) ================================================================================ Priority: id - class - relationship (parent/decendant has unique tags?) ================================================================================ # Return the first matched one # find_element() # Return all matched tags # find_elements() ================================================================================ tag_SearchGNBText=driver.find_element_by_id("SearchGNBText") tag_SearchGNBText.send_keys(keyword) ================================================================================ # Tip tag_SearchGNBText.clear().send_keys(keyword) ================================================================================ # No id # class="search-btn" # CTRL+F search-btn ================================================================================ # Class: . # button.search-btn: from button, find class name search-btn class_search-btn=driver.find_element_by_css_selector(".search-btn") class_search-btn.click() ================================================================================ # Explicit wait # try: # element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.ID,"myDynmicElement"))) # finally: # driver.quit() ================================================================================ # Implicit wait: wait, fast loaded, go # driver.implicitly_wait(10) ================================================================================ # Absolute wait: set 10 sec wait, 10 sec wait This is needed for cloudfare web app ================================================================================ # presence_of_all_element_located: all # presence_of_element_located: speficied one # By.ID # By.CLASS_NAME try: element=WebDriverWait(driver,10).until( EC.presence_of_element_located((By.CLASS_NAME,"oTravelBox"))) except Exception as e: print("error",e) driver.implicitly_wait(10) ================================================================================ # class="oTravelBox" # > next child # class="boxList" found=driver.find_element_by_css_selector(".oTravelBox>.boxList>.moreBtnWrap>.moreBtn") found.click() ================================================================================ # searchModule.SetCategoryList(1,'') for page in range(1,16): try: driver.execute_script("searchModule.SetCategoryList(%s,'')"%page) time.sleep(2) print("%s page"%page) # Product name, comment, period1, period2, price, score, thumbnail, link for detail # # class oTravelBox, from child, class boxList, from child, li boxItems=driver.find_elements_by_css_selector('.oTravelBox>.boxList>') # for li in boxItems: print("Thumbnail",li.find_element_by_css_selector('img').get_attribute('src')) print("Link",li.find_element_by_css_selector('a').get_attribute('onclick')) # h5 tag, class proTit print("Product name",li.find_element_by_css_selector('h5.proTit').text) # print("Comment",li.find_element_by_css_selector('.proSub').text) print("Price",li.find_element_by_css_selector('.proPrice').text) # " " == > for info in li.find_elements_by_css_selector('.info-row .proInfo'): print(info.tex) print("Score",li.find_element_by_css_selector('.proPrice').text) except Exception as e1: print("Error",e1) driver.close() driver.quit() import sys sys.exit()