Guest User

Untitled

a guest
Nov 20th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. const HeadlessChrome = require('simple-headless-chrome')
  2.  
  3. const browser = new HeadlessChrome({
  4. headless: true, // If you turn this off, you can actually see the browser navigate with your instructions,
  5. })
  6.  
  7. async function navigateWebsite(urlToGoTo) {
  8. try {
  9. await browser.init()
  10.  
  11. const mainTab = await browser.newTab({
  12. privateTab: false
  13. })
  14.  
  15. await mainTab.inject('jquery')
  16.  
  17. let cookieName = 'li_at'
  18. let cookieValue = 'cyzzzzzzzzz'
  19. let cookieDomain = '.www.linkedin.com'
  20.  
  21. await mainTab.setCookie(cookieName, cookieValue, {
  22. domain: cookieDomain
  23. })
  24.  
  25. // Navigate to a URL
  26. await mainTab.goTo(urlToGoTo)
  27. await mainTab.wait(2000);
  28.  
  29. // Get a HTML tag value based on class id
  30. let businessName = await mainTab.evaluate(function (selector) {
  31. const selectorHtml = document.querySelector(selector)
  32. return selectorHtml.innerHTML
  33. }, '.org-top-card-module__name');
  34.  
  35. let industry = await mainTab.evaluate(function (selector) {
  36. const selectorHtml = document.querySelector(selector)
  37. return selectorHtml.innerHTML
  38. }, '.company-industries');
  39.  
  40. let followers = await mainTab.evaluate(function (selector) {
  41. const selectorHtml = document.querySelector(selector)
  42. return selectorHtml.innerHTML
  43. }, '.org-top-card-module__followers-count');
  44.  
  45. let details = {
  46. businessName: cleanData(businessName),
  47. industry: cleanData(industry),
  48. followers: cleanData(followers)
  49. }
  50.  
  51. console.log(details)
  52.  
  53.  
  54. // Resize the viewport to full screen size (One use is to take full size screen shots)
  55. await mainTab.resizeFullScreen()
  56.  
  57. // Take a screenshot
  58. await mainTab.saveScreenshot()
  59.  
  60. // Close the browser
  61. await browser.close()
  62.  
  63. return true
  64. } catch (err) {
  65. console.log('ERROR!', err)
  66. }
  67. }
  68.  
  69. let websites = []
  70.  
  71. websites.push('https://www.linkedin.com/company/qrious-limited/')
  72. websites.push('https://www.linkedin.com/company/wentworth-consulting-nz-/')
  73. websites.push('https://www.linkedin.com/company/capita/')
  74.  
  75. websites.forEach(function (i) {
  76. navigateWebsite(i)
  77. })
  78.  
  79.  
  80. function cleanData(a) {
  81. return a.result.value.replace(/(rn|n|r)/gm, "").trim()
  82. }
Add Comment
Please, Sign In to add comment