Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. person_1 = WebDriverWait(self.driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "tr:nth-child(1) > td.personName > a")))
  2. person_1.click()
  3.  
  4. person_profile = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, "profileSectionContent")))
  5. html_source = self.driver.find_element_by_xpath("//table[@id='personSummaryTable']").get_attribute("outerHTML")
  6. f = open('person_1_%s.html'%(company['c_name']), 'w')
  7. f.write(html_source.encode('utf-8'))
  8. f.close()
  9. person_path_1 = 'person_1_%s.html'%(company['c_name'])
  10. cookies = self.driver.get_cookies()
  11.  
  12. with open(person_path_1) as fp:
  13. sel = Selector(text=fp.read())
  14. company['p1c_name'] = sel.xpath("//h1[@itemprop='name']/text()").extract_first().strip("n")
  15. company['p1c_role'] = sel.xpath("//h2[@itemprop='role']/text()").extract_first().strip("n")
  16. company['p1c_phoneNumber'] = sel.xpath("//div[@class='phoneNumber']/text()[position()=2]").extract_first().strip("n")
  17. company['p1c_email'] = sel.xpath("//span[@class='personEmail']/a/text()").extract_first().strip()
  18.  
  19. #Click back to person list
  20. people = self.driver.find_element_by_xpath("//a[@id='personsearch' and @class='categoryTab personTabColor ui-tabs-anchor']")
  21. people.click()
  22. person_2 = WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "tr:nth-child(2) > td.personName > a")))
  23. person_2.click()
  24.  
  25. time.sleep(4)
  26. person_profile = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, "profileSectionContent")))
  27. self.driver.save_screenshot('%s.png'%(company['c_name']))
  28. html_source = self.driver.find_element_by_xpath("//table[@id='personSummaryTable']").get_attribute("outerHTML")
  29. f = open('person_2_%s.html'%(company['c_name']), 'w')
  30. f.write(html_source.encode('utf-8'))
  31. f.close()
  32. person_path_2 = 'person_2_%s.html'%(company['c_name'])
  33. cookies = self.driver.get_cookies()
  34.  
  35. with open(person_path_2) as fp:
  36. sel = Selector(text=fp.read())
  37. company['p2c_name'] = sel.xpath("//h1[@itemprop='name']/text()").extract_first().strip("n")
  38. company['p2c_role'] = sel.xpath("//h2[@itemprop='role']/text()").extract_first().strip("n")
  39. company['p2c_phoneNumber'] = sel.xpath("//div[@class='phoneNumber']/text()[position()=2]").extract_first().strip("n")
  40. company['p2c_email'] = sel.xpath("//span[@class='personEmail']/a/text()").extract_first().strip()
  41.  
  42. yield company
  43.  
  44. <div class="outerResults" style="">
  45. <div class="results searchResults" style="display: block;">
  46.  
  47. <table cellspacing="0" id="resultGroup">
  48. <colgroup>
  49. </colgroup>
  50. <tbody>
  51. <tr>
  52. <td class="selector">
  53. <a href="#" id="p_-1454220127" title="Gary Smith" class="checkbox unchecked">&nbsp;</a>
  54. </td>
  55. <td class="personName">
  56. <a href="#!search/profile/person?personId=-1454220127&targetid=profile">
  57. Gary Smith
  58. </a>
  59. </td>
  60. <td class="title">
  61. Chief Executive Officer and Co-Founder
  62. <input type="hidden" name="" value="Chief Executive Officer and Co-Founder" id="personTitle">
  63. <br>
  64. <div class="companyLink">
  65. <br>
  66. <a href="#!search/profile/company?companyId=104333869&targetid=profile" class="">
  67. Tesla Motors Inc
  68. </a>
  69. </div>
  70. </td>
  71. <td class="contact">
  72. <span class="unmaskContactText">Click to view this profile</span>
  73. <span class="detailContactMask">Email</span>
  74. <span class="upsellContainer" rel="upsellContactInfo">&nbsp;</span><br>
  75. <div class="phoneNumber">
  76. <span class="detailContactMask">Phone</span>
  77. </div>
  78. </td>
  79. <td class="date">
  80. <span class="date" title="Last Update">
  81. 5/21/14
  82. </span>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td class="selector">
  87. <a href="#" id="p_-1832984054" title="Tesla EVs" class="checkbox unchecked">&nbsp;</a>
  88. </td>
  89. <td class="personName">
  90. <a href="#!search/profile/person?personId=-1832984054&targetid=profile">
  91. Tesla EVs
  92. </a>
  93. </td>
  94. <td class="title">
  95. Chief Executive Officer
  96. <input type="hidden" name="" value="Chief Executive Officer" id="personTitle">
  97. <br>
  98. <div class="companyLink">
  99. <br>
  100. <a href="#!search/profile/company?companyId=104333869&targetid=profile" class="">
  101. Tesla Motors Inc
  102. </a>
  103. </div>
  104. </td>
  105. <td class="contact">
  106. <span class="unmaskContactText">Click to view this profile</span>
  107. <span class="detailContactMask">Email</span>
  108. <span class="upsellContainer" rel="upsellContactInfo">&nbsp;</span><br>
  109. <div class="phoneNumber">
  110. <span class="detailContactMask">Phone</span>
  111. </div>
  112. </td>
  113. <td class="date">
  114. <span class="date" title="Last Update">
  115. 6/24/15
  116. </span>
  117. </td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. </div>
  122. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement