Skip to content

Instantly share code, notes, and snippets.

@codewizard13
Created November 6, 2015 20:30
Show Gist options
  • Save codewizard13/aa41d45783ac8647dd52 to your computer and use it in GitHub Desktop.
Save codewizard13/aa41d45783ac8647dd52 to your computer and use it in GitHub Desktop.
/*
FILE: ehCode_2015.11.06_javascript_scrapeLinksFromOneTab_02.txt
CREATOR: Eric Hepperle
DATE: 2015.11.06
This version works with a local .htm(l) file and injects jQuery
via "jquery-injector" plugin, which seems to work now that
jQuerify no longer does.
*/
var strOut = '';
var arrTabGroups = $('#contentAreaDiv > div');
arrTabGroups.each(function(i,v){
var outTabGroup = '';
console.log(i + " ************************************************************ ");
// Define Label for this Tab Group:
var label = $(this).find('div.tabGroupTitleText').html();
var label = typeof label != 'undefined' ? label : "--- NO LABEL: Tab Group # [" + i + "] --";
console.log('label = ' + label);
// Get all links in this tab group:
var links = $(this).find('a.clickable');
console.log('links:');
console.log(links);
// Build formatted label:
var labelText = "<h2 style='background-color:orange; border:solid black 2px; border-radius: 15px;padding: 10px;'>" + label + "</h2>";
console.log(labelText);
// get date time ---> doesn't quite work yet ... selector issue im sure.
var selector = "";
var dateTime = $(this).find(selector).html();
console.log('%c ------> dateTime # %s: <-------',"background:purple;color:white", i);
console.log(dateTime);
// Begin current link list:
var linkList = "<ul style='list-style: none'>";
var linksCount = links.length;
console.log("linksCount = " + linksCount);
// Loop through all links ...
links.each(function(j, v) {
console.log('Link object #: ' + j);
var title = $(this)[0].text;
var url = $(this)[0].href;
console.log('TITLE: ' + title);
console.log('URL: ' + url);
var currentLink = "<li>[" + i +"][" + j + "]: <a href='" + url + "' target='_blank' >" +
title + "</a></li>";
linkList += currentLink;
});
// close current link list
linkList += "</ul>";
// BUILD OUT HTML STRING:
outTabGroup += labelText + linkList + "<hr />";
strOut += outTabGroup;
});
// Launch results in new window:
var win = window.open("", "APPLES");
win.document.body.innerHTML = strOut;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment