[問題] selenium 定位問題

看板Python作者 (發燒夏天)時間6年前 (2018/12/24 14:52), 6年前編輯推噓1(103)
留言4則, 2人參與, 6年前最新討論串1/1
各位版友好: 想請問若我想使用selenium來獲取以下開放式課程網址中, http://ocw.nctu.edu.tw/course_detail-v.php?bgid=6&gid=0&nid=584 內嵌的youtube影片,其標題有來源的連結網址,可以怎麼做呢? 先附上檢查碼: <a class="ytp-title-link yt-uix-sessionlink" target="_blank" data-sessionlink="feature=player-title" href="Lec01" rel="nofollow">https://www.youtube.com/watch?v=gEm12LAoRLw">Lec01
馬克思學說之析評 馬克 思思想出現的時代背景 (1/2)</a> 我目前只能做到如下: from selenium import webdriver Browser = webdriver.Chrome('D:/code/crawler/chromedriver.exe') target_url = 'http://ocw.nctu.edu.tw/course_detail-v.php?bgid=6&gid=0&nid=584' Browser.get(target_url) Browser.find_element_by_id("player") 感謝閱讀 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.239.158 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1545634352.A.931.html

12/24 15:18, 6年前 , 1F
Chrome擴充chroPath
12/24 15:18, 1F
謝謝tom222指導。 我用chroPath檢視影片標題後得到如下結果: rel XPath:It might be child of svg/pseudo/comment/iframe. XPath doesn't support for them. abs XPath:It might be child of iframe & it is not supported currently. CSS sel...:It won't support on chrome store & in blank new tab. Please open any website & try. 請問這是否表示我還沒成功找到定位?謝謝您 ※ 編輯: bewilderment (42.72.239.158), 12/24/2018 15:29:56

12/24 22:53, 6年前 , 2F
ifram=Browser.find_element_by_xpath("//iframe[@src]")
12/24 22:53, 2F

12/24 22:53, 6年前 , 3F
print ifram.get_attribute("src")
12/24 22:53, 3F

12/24 22:54, 6年前 , 4F
不學 xpath 你 selenium 大概抓不到甚麼東西拉...
12/24 22:54, 4F
好的,謝謝s860134。 我一定會去學一下xpath。 感謝指導~ ※ 編輯: bewilderment (42.73.238.129), 12/25/2018 00:16:03 ※ 編輯: bewilderment (42.73.238.129), 12/25/2018 18:03:46
文章代碼(AID): #1S888man (Python)
文章代碼(AID): #1S888man (Python)