html looks like this我已經編寫了這段代碼來清除url中的所有課程。爲此,我試圖使用xpath
來計算課程數量。但它不給我任何東西。我在哪裏做錯了?在selenium-python中使用xpath查找元素文本NOt工作
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait`
class FinalProject:
def __init__(self,url= "https://www.class-central.com/subject/data-science"):`
self.url = url
base_url = 'https://www.class-central.com'
self.error_flag = False
self.driver = webdriver.Chrome(<path to chromedriver>)
self.driver.get(self.url)
sleep(2)
self.count_course_and_scroll()
def count_course_and_scroll(self):
wait = WebDriverWait(self.driver, 30);
ele = wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'Not right now, thanks.')));
ele.click()
print "----------------------POP UP CLOSED---------------------"
total_courses = self.driver.find_element_by_xpath("//span[@id='number-of-courses']")
print total_courses
print total_courses.text
self.driver.close()
fp = FinalProject()
請分享你工作的HTML代碼。 – Jose
你有什麼錯誤嗎? – Guy
@Jose我分享了html的截圖。我不知道我應該如何分享完整的。 –