Guest User

Untitled

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