Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Prompts to create a Chrome bookmarklet to scrape h2 and h3 heading tags on a page. ##
- ## Prompt to scrape H2s:
- 'Create a chrome bookmarklet that scrapes the h2 headings tag and copies them into a list form on my computer clipboard.'
- ## Prompt to scrape H3s:
- Create a chrome bookmarklet that scrapes the h2 headings tag and copies them into a list form on my computer clipboard.
- ## Already created bookmarklet code:
- ### H2 scrape:
- javascript:(function() {
- var h2s = Array.from(document.getElementsByTagName('h2'));
- var h2Texts = h2s.map(function(h2) {
- return h2.textContent;
- });
- var textToCopy = h2Texts.join('\n');
- if (window.navigator && window.navigator.clipboard) {
- window.navigator.clipboard.writeText(textToCopy).then(function() {
- alert('Copied to clipboard');
- }, function(err) {
- alert('Could not copy text: ', err);
- });
- } else {
- var textArea = document.createElement('textarea');
- textArea.value = textToCopy;
- document.body.appendChild(textArea);
- textArea.focus();
- textArea.select();
- try {
- var successful = document.execCommand('copy');
- var msg = successful ? 'successful' : 'unsuccessful';
- alert('Copy command was ' + msg);
- } catch (err) {
- alert('Unable to copy, unsupported browser.');
- }
- document.body.removeChild(textArea);
- }
- })();
- ### H3 scrape:
- javascript:(function() {
- var h3s = Array.from(document.getElementsByTagName('h3'));
- var h3Texts = h3s.map(function(h3) { return h3.textContent; });
- var textToCopy = h3Texts.join('\n');
- if (window.navigator && window.navigator.clipboard) {
- window.navigator.clipboard.writeText(textToCopy).then(function() {
- alert('Copied to clipboard');
- }, function(err) {
- alert('Could not copy text: ', err);
- });
- } else {
- var textArea = document.createElement('textarea');
- textArea.value = textToCopy;
- document.body.appendChild(textArea);
- textArea.focus();
- textArea.select();
- try {
- var successful = document.execCommand('copy');
- var msg = successful ? 'successful' : 'unsuccessful';
- alert('Copy command was ' + msg);
- } catch (err) {
- alert('Unable to copy, unsupported browser.');
- }
- document.body.removeChild(textArea);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement