Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const HeadlessChrome = require('simple-headless-chrome')
- const browser = new HeadlessChrome({
- headless: true, // If you turn this off, you can actually see the browser navigate with your instructions,
- })
- async function navigateWebsite(urlToGoTo) {
- try {
- await browser.init()
- const mainTab = await browser.newTab({
- privateTab: false
- })
- await mainTab.inject('jquery')
- let cookieName = 'li_at'
- let cookieValue = 'cyzzzzzzzzz'
- let cookieDomain = '.www.linkedin.com'
- await mainTab.setCookie(cookieName, cookieValue, {
- domain: cookieDomain
- })
- // Navigate to a URL
- await mainTab.goTo(urlToGoTo)
- await mainTab.wait(2000);
- // Get a HTML tag value based on class id
- let businessName = await mainTab.evaluate(function (selector) {
- const selectorHtml = document.querySelector(selector)
- return selectorHtml.innerHTML
- }, '.org-top-card-module__name');
- let industry = await mainTab.evaluate(function (selector) {
- const selectorHtml = document.querySelector(selector)
- return selectorHtml.innerHTML
- }, '.company-industries');
- let followers = await mainTab.evaluate(function (selector) {
- const selectorHtml = document.querySelector(selector)
- return selectorHtml.innerHTML
- }, '.org-top-card-module__followers-count');
- let details = {
- businessName: cleanData(businessName),
- industry: cleanData(industry),
- followers: cleanData(followers)
- }
- console.log(details)
- // Resize the viewport to full screen size (One use is to take full size screen shots)
- await mainTab.resizeFullScreen()
- // Take a screenshot
- await mainTab.saveScreenshot()
- // Close the browser
- await browser.close()
- return true
- } catch (err) {
- console.log('ERROR!', err)
- }
- }
- let websites = []
- websites.push('https://www.linkedin.com/company/qrious-limited/')
- websites.push('https://www.linkedin.com/company/wentworth-consulting-nz-/')
- websites.push('https://www.linkedin.com/company/capita/')
- websites.forEach(function (i) {
- navigateWebsite(i)
- })
- function cleanData(a) {
- return a.result.value.replace(/(rn|n|r)/gm, "").trim()
- }
Add Comment
Please, Sign In to add comment