2016-07-16 53 views
-1

我用硒颳去angel.co數據,但仍然沒有得到的數據從網站無法使用硒

from scrapy import Request,Spider 

import urllib 
from selenium import webdriver 

class AngelSpider(Spider): 
    name = "angel" 
    allowed_domains = ["angel.co"] 
    AJAXCRAWL_ENABLED = True 
    start_urls = (
     "https://angel.co/companies?locations[]=India", 
    ) 

    def __init__(self): 
     self.path ='/usr/lib/chromium-browser/chromedriver' 
     self.driver = webdriver.Chrome(self.path) 

    def parse(self,response): 
     self.driver.get(response.url) 
     self.driver.implicitly_wait(50) 
     while True: 
      next = self.driver.find_element_by_css_selector("div.more") 
      try: 
       next.click() 
       self.driver.implicitly_wait(10) 
       divs = self.driver.find_element_by_xpath("//div[@class= 'results']") 
       for div in divs: 
        name =divs.find_element_by_css_selector("div.name") 
        print name.text 
      except: 
       break 

回答

0

你什麼也看不到印刷的原因是,您使用的是裸除了抽取數據條款和基本上默默地忽略所有提出的異常

的問題是在你發現頁面上的元素的方式,在這條線,你是因爲你正在使用find_element_by_xpath()方法定位一個div元素:

divs = self.driver.find_element_by_xpath("//div[@class= 'results']") 

divsWebElement實例現在這沒有可迭代,遍歷它會失敗的下一行:

for div in divs: 

相反,你在忙什麼是這樣的:

results = self.driver.find_elements_by_css_selector(".results > div") 
for result in results: 
    name = result.find_element_by_css_selector(".name") 
    print(name.text) 
+0

仍無法刮@alecxe用於'VAL = response.xpath( 「// DIV [@數據_tn = '公司/結果']」) COMPANY_NAME = val.xpath(「// DIV [提取()'這兩個提取器以及這些xpaths在鉻上正常工作,但沒有給我的蜘蛛任何結果 –

+0

無法弄清楚我在做什麼錯誤。抓取後沒有獲得數據,所有的xpath都沒問題。 –