2015-06-27 30 views
0

我試圖從https://www.google.com/trends/home/all/IN刮圖片,網址,說明從

這裏獲得的圖像和視頻的網址是代碼:

driver = webdriver.PhantomJS('/usr/local/bin/phantomjs') 
driver.set_window_size(1124, 850) 
driver.get("https://www.google.com/trends/home/all/IN") 
trend = {} 
def getGooglerends(): 
    try: 
    #Does this line makes any sense 
     #element = WebDriverWait(driver, 20).until(lambda driver: driver.find_elements_by_class_name('md-list-block ng-scope')) 
     for s in driver.find_elements_by_class_name('md-list-block ng-scope'): 
      print s.find_element_by_tag_name('img').get_attribute('src') 
      print s.find_element_by_tag_name('img').get_attribute('alt') 
      print s.find_elements_by_class_name('image-wrapper ng-scope').get_attribute('href') 
    except: 
     getNDTVTrends() 
getGooglerends() 

這給

WebDriverException: Message: {"errorMessage":"Compound class names not permitted","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"111","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:57213","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"class name\", \"sessionId\": \"648251c0-1cc7-11e5-bf1c-4ff79ddbdce4\", \"value\": \"md-list-block ng-scope\"}","url":"/elements","urlParsed":{"anchor":"","query":"","file":"elements","directory":"/","path":"/elements","relative":"/elements","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/elements","queryKey":{},"chunks":["elements"]},"urlOriginal":"/session/648251c0-1cc7-11e5-bf1c-4ff79ddbdce4/elements"}} 
Screenshot: available via screen 

任何建議的這個錯誤?

回答

1

化合物類別名稱不允許

它基本上意味着,你不能在你的類名空間。你需要切換到另一個選擇器,是該CSS,Xpath或類似的東西。

不能確定你想選擇哪種方法,但是,例如下面的XPath選擇包含該類項目的列表:

//div[@class="homepage-trending-stories generic-container ng-scope"]/md-list[@class="md-list-block ng-scope"] 
+0

我試圖讓圖像鏈接,descrption和文章鏈接從https:/ /www.google.com/trends/home/all/IN頁面。你能幫忙嗎? – nlper