I am trying to print the result on the terminal but getting this error message:
IndexError: list index out of range
Below is the code, thanks in advance for your help.
Truly beginner to this field.
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("excludeSwitches", ['enable-automation'])
# Pass the argument 1 to allow and 2 to block
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
driver = webdriver.Chrome(chrome_options=option, executable_path='C:\Users\Sheik\Desktop\web crawling\chromedriver.exe')
driver.implicitly_wait(5000)
url = "https://www.yell.com/"
driver.get(url)
search_query_path = driver.find_element_by_xpath('''//*[@id="search_keyword"]''')
search_query_path.click()
search_query_path.send_keys("Garage Services")
search_city_path = driver.find_element_by_xpath('''//*[@id="search_location"]''')
search_city_path.click()
search_city_path.send_keys("London")
search_btn = driver.find_element_by_xpath('''//*[@id="searchBoxForm"]/fieldset/div[1]/div[3]/button''')
search_btn.click()
names = driver.find_elements_by_class_name("businessCapsule--name")
address = driver.find_elements_by_class_name("businessCapsule--address")
num_page_items = len(names)
for i in range(num_page_items):
print(f"{names[num_page_items].text} : {address[num_page_items].text}")
driver.close()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…