我正在为我的学术项目报废booking.com。我需要抓取酒店类别类型,无论给定的酒店是酒店,公寓式酒店还是别墅等。每个酒店都将转到新链接,并且每个酒店的类别有两个不同的类别。
我使用了硒Web驱动程序和漂亮的汤,但结果不正确,也找不到类(错误消息:消息:无法找到元素:// span [@class ='bui-badge bh-property-类型bh-property-type--constructive-dark']
booking.com的1类
booking.com上的2类
Environment.GetEnvironmentVariable("yoursettingskey");
我试图提取最近两天的类别名称,但未成功。请帮忙。
答案 0 :(得分:0)
输入WebDriverWait
,然后等待visibility_of_element_located
(),然后获得类别名称。我已经在chrome浏览器上进行了测试。它工作正常。
代码:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time
from bs4 import BeautifulSoup
from itertools import zip_longest
#downlod the compatible chrome driver from following website https://chromedriver.chromium.org/downloads
driver=webdriver.Chrome(executable_path="path/to/chromedriver")
names = []
links = []
driver.get("https://www.booking.com/searchresults.en-gb.html?label=gen173nr-1DCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AED6AEBiAIBqAIDuALAlIX0BcACAQ&lang=en-gb&sid=643f8d88e23b09ce396d7959aaad4b9e&sb=1&sb_lp=1&src=index&src_elem=sb&error_url=https%3A%2F%2Fwww.booking.com%2Findex.en-gb.html%3Flabel%3Dgen173nr-1DCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AED6AEBiAIBqAIDuALAlIX0BcACAQ%3Bsid%3D643f8d88e23b09ce396d7959aaad4b9e%3Bsb_price_type%3Dtotal%26%3B&ss=Auckland&is_ski_area=0&ssne=Auckland&ssne_untouched=Auckland&dest_id=-1506909&dest_type=city&checkin_year=2020&checkin_month=7&checkin_monthday=1&checkout_year=2020&checkout_month=7&checkout_monthday=15&group_adults=2&group_children=0&no_rooms=1&b_h4u_keep_filters=&from_sf=1")
time.sleep(5)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
#Getting the hotel name
for item in soup.findAll('span', {'class': 'sr-hotel__name'}):
names.append(item.get_text(strip=True))
#Getting the link of each hotel
for item in soup.findAll("a", {'class': 'hotel_name_link url'}):
item = item.get("href").strip()
links.append("https://www.booking.com{}".format(item))
print(links)
final = []
for item in zip_longest(names, links):
final.append(item)
df5 = pd.DataFrame(
final, columns=['Names', 'links'])
#Getting the hotel category by opening each hotel link
category = []
for item in df5['links']:
driver.get(item)
WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"h2#hp_hotel_name")))
# Extracting from class 1
try:
job_title = driver.find_element_by_xpath("//span[@class = 'hp__hotel-type-badge']").text
category.append(job_title)
# Extracting from class 2
except:
job_title = driver.find_element_by_xpath("//span[@class = 'bui-badge bh-property-type bh-property-type--constructive-dark']").text
category.append(job_title)
print(category)
输出:
链接:
['https://www.booking.com/hotel/nz/naumi-auckland-airport.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4327023_207636943_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=1&highlighted_blocks=4327023_207636943_2_2_0&hpos=1&no_rooms=1&sr_order=popularity&sr_pri_blocks=4327023_207636943_2_2_0__187720&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/kiwi-international-airport.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4307307_248627375_2_34_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=2&highlighted_blocks=4307307_248627375_2_34_0&hpos=2&no_rooms=1&sr_order=popularity&sr_pri_blocks=4307307_248627375_2_34_0__156800&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/oaks-smartstay-residence.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=3715901_195766824_0_0_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=3&highlighted_blocks=3715901_195766824_0_0_0&hpos=3&no_rooms=1&sr_order=popularity&sr_pri_blocks=3715901_195766824_0_0_0__194400&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=;has_campaign_deals_getaway20_customer_label=1#hotelTmpl', 'https://www.booking.com/hotel/nz/kiwi-international.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4306910_145188713_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=4&highlighted_blocks=4306910_145188713_2_2_0&hpos=4&no_rooms=1&sr_order=popularity&sr_pri_blocks=4306910_145188713_2_2_0__82600&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/airport-garden-inn-amp-conference-centre.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=368872401_119516889_0_2_3&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=5&highlighted_blocks=368872401_119516889_0_2_3&hpos=5&no_rooms=1&sr_order=popularity&sr_pri_blocks=368872401_119516889_0_2_3__132300&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=;has_campaign_deals_getaway20_customer_label=1#hotelTmpl', 'https://www.booking.com/hotel/nz/jet-park-airport-conference-centre.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4323907_132260303_0_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=6&highlighted_blocks=4323907_132260303_0_2_0&hpos=6&no_rooms=1&sr_order=popularity&sr_pri_blocks=4323907_132260303_0_2_0__186728&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/ventura-inn-suites-auckland-airport.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4322906_148307165_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=7&highlighted_blocks=4322906_148307165_2_2_0&hpos=7&no_rooms=1&sr_order=popularity&sr_pri_blocks=4322906_148307165_2_2_0__197460&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/airport-gateway.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4649004_248627361_3_34_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=8&highlighted_blocks=4649004_248627361_3_34_0&hpos=8&no_rooms=1&sr_order=popularity&sr_pri_blocks=4649004_248627361_3_34_0__235200&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/auckland-airport-motel.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=26933802_248627359_4_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=9&highlighted_blocks=26933802_248627359_4_2_0&hpos=9&no_rooms=1&sr_order=popularity&sr_pri_blocks=26933802_248627359_4_2_0__224000&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/grand-chancellor-auckland-city.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4312701_199559564_0_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=10&highlighted_blocks=4312701_199559564_0_2_0&hpos=10&no_rooms=1&sr_order=popularity&sr_pri_blocks=4312701_199559564_0_2_0__245310&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/aucklands-waitakaere-estate.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=25639707_92677386_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=11&highlighted_blocks=25639707_92677386_2_2_0&hpos=11&no_rooms=1&sr_order=popularity&sr_pri_blocks=25639707_92677386_2_2_0__237204&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/formule1-auckland.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=31939007_94407293_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=12&highlighted_blocks=31939007_94407293_2_2_0&hpos=12&no_rooms=1&sr_order=popularity&sr_pri_blocks=31939007_94407293_2_2_0__210000&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/novotel-auckland-airport.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=27270502_95454373_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=13&highlighted_blocks=27270502_95454373_2_2_0&hpos=13&no_rooms=1&sr_order=popularity&sr_pri_blocks=27270502_95454373_2_2_0__352600&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/president-hotel-auckland.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4310701_250543755_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=14&highlighted_blocks=4310701_250543755_2_2_0&hpos=14&no_rooms=1&sr_order=popularity&sr_pri_blocks=4310701_250543755_2_2_0__126350&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/auckland-airport-traveller-39-s-international-motor-inn.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=101416508_105828529_0_34_3&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=15&highlighted_blocks=101416508_105828529_0_34_3&hpos=15&no_rooms=1&sr_order=popularity&sr_pri_blocks=101416508_105828529_0_34_3__128800&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=;has_campaign_deals_getaway20_customer_label=1#hotelTmpl', 'https://www.booking.com/hotel/nz/ramada-suites-victoria.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=548340701_198584400_0_0_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=16&highlighted_blocks=548340701_198584400_0_0_0&hpos=16&no_rooms=1&sr_order=popularity&sr_pri_blocks=548340701_198584400_0_0_0__162099&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/cordis-auckland.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4312114_231885437_0_42_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=17&highlighted_blocks=4312114_231885437_0_42_0&hpos=17&no_rooms=1&sr_order=popularity&sr_pri_blocks=4312114_231885437_0_42_0__218646&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/surf-and-snow-backpackers.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=24493710_104185625_0_0_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=18&highlighted_blocks=24493710_104185625_0_0_0&hpos=18&no_rooms=1&sr_order=popularity&sr_pri_blocks=24493710_104185625_0_0_0__54698&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/copthorne-auckland-anzac-avenue.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4321930_91457160_0_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=19&highlighted_blocks=4321930_91457160_0_2_0&hpos=19&no_rooms=1&sr_order=popularity&sr_pri_blocks=4321930_91457160_0_2_0__172480&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/kingsgate-parnell.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4324210_91901131_2_42_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=20&highlighted_blocks=4324210_91901131_2_42_0&hpos=20&no_rooms=1&sr_order=popularity&sr_pri_blocks=4324210_91901131_2_42_0__182434&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/quality-inn-manukau.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4312404_91901050_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=21&highlighted_blocks=4312404_91901050_2_2_0&hpos=21&no_rooms=1&sr_order=popularity&sr_pri_blocks=4312404_91901050_2_2_0__137340&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/sudima-auckland-airport.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=26733201_91470131_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=22&highlighted_blocks=26733201_91470131_2_2_0&hpos=22&no_rooms=1&sr_order=popularity&sr_pri_blocks=26733201_91470131_2_2_0__237100&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/the-spencer-on-byron.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4319437_91457096_2_2_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=23&highlighted_blocks=4319437_91457096_2_2_0&hpos=23&no_rooms=1&sr_order=popularity&sr_pri_blocks=4319437_91457096_2_2_0__286740&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/oaks-smartstay-on-hobson.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=4316910_248627369_2_1_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=24&highlighted_blocks=4316910_248627369_2_1_0&hpos=24&no_rooms=1&sr_order=popularity&sr_pri_blocks=4316910_248627369_2_1_0__235200&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl', 'https://www.booking.com/hotel/nz/vr-queen-street.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaK4BiAEBmAEJuAEXyAEP2AEB6AEBiAIBqAIDuALAlIX0BcACAQ&sid=5b45c0c12d9b33b60a64410845136296&all_sr_blocks=101673102_248627330_2_34_0&checkin=2020-07-01&checkout=2020-07-15&dest_id=-1506909&dest_type=city&group_adults=2&group_children=0&hapos=25&highlighted_blocks=101673102_248627330_2_34_0&hpos=25&no_rooms=1&sr_order=popularity&sr_pri_blocks=101673102_248627330_2_34_0__179000&srepoch=1585560104&srpvid=bc6741d37734006e&ucfs=1&from=searchresults\n;highlight_room=#hotelTmpl']
类别:
['Hotel', 'Hotel', 'Aparthotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Motel', 'Aparthotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hostel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Hotel', 'Aparthotel', 'Aparthotel']
更新:
更改最后几行代码,看看是否有任何区别。
#Getting the hotel category by opening each hotel link
category = []
for item in df5['links']:
driver.get(item)
WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"h2#hp_hotel_name")))
try:
job_title = driver.find_element_by_css_selector("h2#hp_hotel_name>span").text
category.append(job_title)
except:
category.append("None")
print(category)