Copy a variable amount of text from a web page

Hi,

I would like to highlight text from a series of webpages, my problem is the amount of text could change in length, The origin will stay the same each time. In an ideal world I would be able to drag mouse to a certain point and highlight text but the position of the last bullet point (below) changes. This means that the highlighted portion could be to big / small. As the next step in the macro would be to copy the highlighted text.

For E.G:

This paragraph will always be here, but it could change length. The text will always start at the same spot so that is easy to click a mouse at the that point. The paragraph will always be followed with the following....

Description

  • then a series of bullet points

  • number of bullets may change

  • but I want to copy down to this last bullet point

I hope the above makes sense and if anyone has any suggestions I would be very grateful.

Thanks,

Mark

Instead of trying to select only the desired part of the text, I would do it like this:

Select all (⌘A)-> copy all to clipboard (⌘C) -> filter the undesired parts from the clipboard (e.g. with some regex action) -> write it to sequentially numbered files (or append it to a big one)

This is probably doable with a bit of web page investigation and JavaScript in Browser.
Most likely the web page section of interest is all encapsulated within one major tag, typically a <div> tag. Or maybe starts with the same tag, and then always includes a few other tags, even though the content can vary.

If you will post the HTML code of the section of interest in a Code Block, I will take a look. You can use the Chrome/Safari Inspect tool to get this.

Hi,

Very interesting concept. I hope that I have copied the html code correctly. If you need any further information please let me know. Thanks very much.

The actual portion is in div class="content" below


<div class="content">
<div class="tabhead active first last" id="accessibletabscontent0-0" tabindex="-1">
<a href="">I Don't want this line</a> <span class="glyphicon"></span>
</div>
<div class="tabbody" style="display: block;">
<div class="tab-details">
<p>I want this paragraph.<br><br>Want this.</p>
<p class="product-features-heading">
I want this line</p>
<ul>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
The highlight should stop at the end of this line</li>
</ul>
</div></div>
</div>

For a code block you have to use grave accents (aka backticks), not straight single quotes. You find the grave accent on the keyboard just left to the “1”, above the Tab key (US keyboard layout).

(On non-US keyboards it may be to the right of the left shift key.)

Thanks for posting, but, no, you did not provide the ACTUAL HTML code from the web page of interest. Do NOT makeup the HTML. Open the web page, inspect, and copy the HTML around the target area. As @Tom noted, you much use the back quote, exactly as show in this: How to Use Code Blocks in the Forum.

After you post the ACTUAL HTML, then you can provide some comments about what you want and don't want.

It would also be good if you could provide the actual URL of the target web page.

<div class="content">
<div class="tabhead active first last" id="accessibletabscontent0-0" tabindex="-1">
<a href="">I Don't want this line</a> <span class="glyphicon"></span>
</div>
<div class="tabbody" style="display: block;">
<div class="tab-details">
<p>I want this paragraph.<br><br>Want this.</p>
<p class="product-features-heading">
I want this line</p>
<ul>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
Want</li>
<li>
The highlight should stop at the end of this line</li>
</ul>
</div></div>
</div>

Bit odd that you say that I have made up the html. I have done no such thing. This is the ACTUAL HTML code from the web page of interest. Only thing that has been changed is my commenting of the English to make it easier to understand what I want. HTML surrounding those comments has not been altered. If the HTML looks "made up" that is purely down to whomever wrote the code.

My apologies but I cannot give you access to the website as you need to log in to gain access. It is a wholesale supplier and an account setup is needed.

With a bit of luck the above code is pasted correctly.

Thanks and if I can provide any more information please let me know

It seems there is a misunderstanding:

When @JMichaelTX says “HTML code” I’m pretty sure he means the whole HTML part of the page (as opposed to JavaScript footers, for instance). This includes the HTML tags as well as the text in-between.

When you say “HTML code” it seems what you actually mean is ‘HTML tags’.

So, when he said your code was “made up” he isn’t referring to the tags, he means the whole thing. What he wants is a real-world sample without any placeholders, substitutions or comments.

And I can confirm: it can be very frustrating to work with a made-up example, because often —after having written a complex filter or regex— it turns out that it actually isn’t reflecting the real-world sample in the way the user has thought.

And that’s also the reason why an actual URL is important.

However, in your case (privacy concerns and access restrictions) I guess it’s impossible for you to deliver any better.

Thanks for your reply.

Unfortunately I have no experience with coding. All I did was Right mouse click in the portion I wanted to inspect. Made sure that the portion I wanted was highlighted. Did edit HTML and copied all. I assumed (by your post, incorrectly) that this was the HTML code.

It's seems that with the restriction of access to a sample url, and my lack of understanding what HTML code looks like, that this may be a no goer and I will have to come up with an alliterative solution.

I will give it a couple of days and close the post.

Thanks for all your help

OK, this looks fine.
Assuming that the first element with a class = "tab-details" is the <div class="tab-details"> shown, then this script/macro should work.
Just open the web page of interest, and trigger this macro.


Example Results

image


MACRO:   Select Text on Page Based on Tag Class


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/8/2/8243357e4c66de0d3a7d2c7db95fa5fe7ba8bd42.kmmacros">Select Text on Page Based on Tag Class.kmmacros</a> (6.9 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



![image|532x906](upload://qu56WNG2eKioEdesNPNhzUx9VZZ.jpg)

---

Please let us know if this works for you.

Questions?
2 Likes

That looks perfect.

I am travelling for the next day or two but I will test ASAP and let you know.

Thanks very much for your efforts

1 Like

Hi,

Sorry for the late reply, had no time to test the macro.

Tested it today and it works great. Thanks very much for all your help.

1 Like