Guest User

Untitled

a guest
Dec 1st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. class PortalSpider(Spider):
  2. name = 'portal'
  3. allowed_domains = ['portal.milvus.com.br']
  4. start_urls = ['https://portal.milvus.com.br/#/help-desk/chamados/aguardando-atendimento']
  5. def start_requests(self):
  6. url = 'https://portal.milvus.com.br/#/help-desk/chamados/aguardando-atendimento'
  7. self.driver = webdriver.Chrome('D:/Area de trabalho/milvus/milvus/chromedriver')
  8. self.driver.get('https://portal.milvus.com.br/#/login')
  9. sleep(5)
  10. username = self.driver.find_element_by_id("username")
  11. password = self.driver.find_element_by_id("password")
  12. username.send_keys("111111")
  13. password.send_keys("111111")
  14. self.driver.find_element_by_xpath('//button').click()
  15. sleep(5)
  16. self.driver.find_element_by_xpath('//*[@id="page-heading"]/div[3]/div/div[1]/div[1]/div[1]/a/div[1]/span').click()
  17. sleep(5)
  18. #sel = Selector(text=self.driver.page_source)
  19.  
  20. yield self.make_requests_from_url(url)
  21.  
  22. def parse(self, response):
  23. chamados = response.xpath('//*[@id="table-chamados"]/tbody/tr/td//@href').extract()
  24. for chamado in chamados:
  25. url = 'https://portal.milvus.com.br/' + str(chamado)
  26. print(self.make_requests_from_url(url))
  27. yield Request(url, callback=self.parse_chamado)
  28.  
  29. #next_page = sel.xpath('//a[text()="Próximo"]/@href').extract()
  30. #url_next = 'https://portal.milvus.com.br/'+ next_page
  31. #yield Request(url_next)
  32.  
  33. def parse_chamado(self, response):
  34. chamado = response.xpath('//*[@id="page-heading"]/h1/text()').extract()
  35. unidade = response.xpath('//*[@id="wrap"]/div/form/div[2]/div/div[2]/div/div[1]/div[1]/div/div[1]/div/div[1]/div/div[2]/select-padrao/div/div/a/span[2]/span/text()').extract()
  36. categoria_pri = response.xpath('//*[@id="wrap"]/div/form/div[2]/div/div[2]/div/div[1]/div[1]/div/div[1]/div/div[2]/div/div[2]/select-padrao/div/div/a/span[2]/span/text()').extract()
  37. categoria_sec = response.xpath('//*[@id="wrap"]/div/form/div[2]/div/div[2]/div/div[1]/div[1]/div/div[1]/div/div[2]/div/div[3]/select-padrao/div/div/a/span[2]/span/text()').extract()
  38. tecnico = response.xpath('//*[@id="wrap"]/div/form/div[2]/div/div[2]/div/div[1]/div[1]/div/div[1]/div/div[2]/div/div[4]/select-padrao/div/div/a/span[2]/span/text()').extract_first()
  39.  
  40. yield{'chamado':chamado,
  41. 'unidade': unidade,
  42. 'categoria principal':categoria_pri,
  43. 'categoria secundaria':categoria_sec,
  44. 'tecnico':tecnico}
Add Comment
Please, Sign In to add comment