Copy paragraph from web with heading, link, and date-time

safari
webscrape
shellscript
xpath
jxa

#1

Note, this macro requires the custom action plugin at:

Macro: click somewhere in a line of text in Safari or Chrome,
and trigger the macro to copy:

  • the enclosing paragraph (as Markdown)
  • any preceding heading
  • a link to the document
  • the date and time

Copy paragraph from web with heading, link, and date.kmmacros (22.8 KB)


Read text and attributes of web items by XPath
#2

Hey, Rob, thanks for another great macro.

May I suggest that you allow for a selection in addition to clicking somewhere?
I would find that more useful since just clicking pulls just a small portion of the text I want.

Thanks.


#3

May not get around to it before the end of the week, but in the meanwhile, if you want to have a try:

  1. Get the .focusNode of the selection, as well as the .anchorNode,
  2. write an XPath expression which finds the nearest common ancestor of the two nodes, and
  3. apply the mdString() function to that shared ancestor.

For the common ancestor XPath, see this discussion:

( PS if you don’t need Markdown, you can just evaluate .toString() on the selection object )


#4

@ComplexPoint First, thank you for sharing this macro. Very useful.

By any chance, did either you or @JMichaelTX, get around to making one that can also act on a selection in the browser?

I do not know Javascript, and therefore am not even able to try and figure the common ancestor suggestion that you have made here.


#5

Please post this question as a NEW topic, and be much more specific about what you are requesting. Please provide a real-world example of the web page (including URL), and exactly what you would like the results to look like.

Also, please see:
Tip: How Do I Get The Best Answer in the Shortest Time?