Skip to content

Instantly share code, notes, and snippets.

@irwinwilliams
Created March 31, 2023 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irwinwilliams/e7fa48e85710bb0861e920bb1ef7af6e to your computer and use it in GitHub Desktop.
Save irwinwilliams/e7fa48e85710bb0861e920bb1ef7af6e to your computer and use it in GitHub Desktop.
GPT3-prompt to use jquery to extract html data
/*
jQuery to select all the values of the last column of 17 rows of an html table, where there are 8 columns. The values are actually anchor tags, which contain img tags. Extract the src attribute from those tags.
In the resulting JavaScript, also import jQuery via dynamically adding it to the page within the javascript, not via a script tag
*/
// Dynamically add jQuery to the page
let script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://code.jquery.com/jquery-3.6.0.min.js';
document.head.appendChild(script);
// Wait for jQuery to load
script.onload = function() {
// Select the last column of the table
let tdList = $('table tr td:last-child');
// Extract the src attribute from the img tags within the anchor tags
let srcList = tdList.find('a img').map(function() {
return $(this).attr('src');
}).get();
// Log the results
console.log(srcList);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment