2016-07-29 1 views
0

私はこのビデオのlinkの名前を掻きたい "狂気の女は払い戻しを欲しがっている人にクレイジーです"です。セレンpython3を使用してビデオのスクレーピング見出し

ウェブ上のコードは次のとおりです。

<span id="eow-title" class="watch-title" dir="ltr" title="Insane Woman Goes Crazy On Guy Who Just Wants A Refund"> 
Insane Woman Goes Crazy On Guy Who Just Wants A Refund 

私はこの方法でやっている:

AttributeError: 'list' object has no attribute 'text'

があります:として

browser = webdriver.Firefox() 
browser.get("https://www.youtube.com/watch?v=POk-uOQSJVk") 
head = browser.find_elements_by_class_name('watch-title') 
print(head.text) 

それは促しています間違っている?

答えて

0

まず、find_elements_by_class_name() methodは、WebElementのリストを返します。一方は1つ必要ですが、です。また、あなたはlet the page load until the desired element is presentする必要があります。

from selenium import webdriver 

from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 


browser = webdriver.Firefox() 
browser.get("https://www.youtube.com/watch?v=POk-uOQSJVk") 

# wait for the presence of the video title 
element = WebDriverWait(browser, 10).until(
    EC.presence_of_element_located((By.ID, "eow-title")) 
) 
print(element.text) 

browser.close() 

プリント:答えを受け入れるために残さ

Insane Woman Goes Crazy On Guy Who Just Wants A Refund 
+0

うわー.. Booommm ...達し親愛なる... 3分。 – user6575792

+0

も機能しています。 'head = browser.find_elements_by_class_name( 'watch-title') 頭の溝の場合​​: print(ditch.text)' – user6575792

関連する問題