html looks like this私はこのコードを書いて、URLからすべてのコースを削っています。このため私はxpath
を使ってコース数を取得しようとしています。しかし、それは私に何も与えません。どこが間違っているの?セレン - パイソンで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のスクリーンショットを共有しました。私は完全なものをどのように共有すべきか分かりません。 –