RegEx - How to Add Anything After Selected Characters - search

I am trying to add rel="nofollow noopener" target="_blank" to all the links in HTML.
Here's the example HTML code:
<li>Some website</li>
<li>Awesome Website</li>
<li>Cool Website</li>
<p>Also check this website</p>!
I know nothing about RegEx but after reading some resources I have written
href([^>]*)
Which selects all the links but I'm not sure how would I add rel="nofollow noopener" target="_blank" in Notepad++ after what I've selected :)
I am trying to add rel="nofollow noopener" target="_blank" to all the links with RegEx

Lets say you have a single HTML file open you'd go through following steps. Be careful with these options and create a backup beforehand.
Ctrl+H
Find what: (href([^>]*)) or shortened and better (href[^>]*)
Replace with: $1 target="_blank" rel="nofollow noopener"
Search mode: Regular expression
Click on Replace All (at your own risk!)
This is resulting in:
For multiple HTML files, you may want to try Find in Files for your needs (Ctrl+Shift+F).

Related

How to remove <div ...> tags in a Excel cell with much HTML code?

i scraped datas from a website using Python. The results are great.
Just the after-work-party is something annoying.
The HTML source code is (of course) messed up with various kind of div class="abc123"> tags.
Do we have an Excel geek-trick to remove them quickly?
I search a <div ...> tag manually and remove the specified one via search'n replace function.
After I jump to the next div tag and so on....
Isn't it a little bit too much of the "good old school" way to remove it?
Of course, there are some online services (free and paid) to do that, but I'm sure we have a trick in Excel, I just can't get it out right now. And using external services like an online tool for cleaning HTML code is again a extra workload - unnecessary.
After experimenting around with some RegEx I was able to solve my problem:
Pressing Ctrl + H for opening Find and Replace then entering my pattern <div *> and replacing it with - whatever:
Find what: <div *>
Replace with:
That's it. Finally.

Add new attributes on element HTML in KB cognitive Services

I want to set new attributes on element html (a or b) in answers intent.
I tried to paste the element <a href="#" onclick="try{console.log("test");}catch(i){}>Operatore</a> and the portal remove always the attribute onclick. I tried also <a href="#" onclick:try{console.log("test");}catch(i){} >Operatore</a> with result negative.
There is a way for set attribute on elements html?
Direct adding option is not yet fully functional. Instead, follow the alternative relative approach.
Use Curl tool for this operation.
From the settings tab of knowledge base, select the CURL tab.
Copy the command to the editable environment.
Follow the steps mentioned in the documentation.

Extract multiple image links from a single div tag that has no class name

Hi I have this HTML code from a website: I want to be able to extract multiple images, I have cases where there is 3-4 images. How would I go about doing that?
<div style="float: right;"><u>Chakra required:</u>
<img src="https://naruto-arena.net/images/energy/energy_2.gif">
<img src="https://naruto-arena.net/images/energy/energy_4.gif">
</div>
My code:
chakras1 = soup.find_all("div")[42].img['src']
print(chakras1)
Result:
https://naruto-arena.net/images/energy/energy_2.gif
I only get the FIRST image but now the second one.
To extract multiple images from within a tag, I personally stick to using for loops. So what I mean is once you find the div tag that you want to look within and say you call that chakras1, I would write the following:
for img in chakras1.find_all("img"):
print(img)
For me the steps kind of go as follows:
find the specific tags you are looking for (img src)
see what tag those tags are within (
navigate through the HTML to that tag (using beautiful soup's .find or .find_all functions depending on what you want to use)
once you have navigated to the tag search within that tag for the tags you're really looking for.
One quick note, with this method, if you are looking through multiple div tags, you're also going to need to loop through those as well.
I hope this makes sense!

Kentico 9 search result transformation

We've noticed a bug when looking at French search results. in the CMS Desk, i've kept the Page Name in English for the French content. The issue is, these are showing on the French results page.
in the transformation, based off the default one, I present the clickable title like this:
<a href='<%# SearchResultUrl() %>' data-type="title" target="_blank" ><%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), ""))), "<span class='highLight'>", "</span>")%></a>
Here's my thinking, if the Menu Caption is filled out, use that rather than title. How do i output DocumentMenuCaption without adjust the search fields on the menu page type?
I think my logic is, check if DocumentMenuCaption is emtpy, if it use, use Title.
You should be able to continue using GetNotEmpty and just pass in the DocumentMenuCaption first, something like this:
<%# GetNotEmpty(GetSearchValue("DocumentMenuCaption");Eval("Title")) %>
You may or may not need the "GetSearchValue" function, but that allows you to grab values from the object that may not be available in the default set of columns for the search results.
Alternatively, you should be able to use the IfEmpty() method:
<%# IfEmpty(GetSearchValue("DocumentMenuCaption"), Eval("Title"), GetSearchValue("DocumentMenuCaption")) %>
Both transformation methods taken from here (double check syntax on "GetNotEmpty" as there are different ways it's implemented: https://docs.kentico.com/k9/developing-websites/loading-and-displaying-data-on-websites/writing-transformations/reference-transformation-methods
You can read more about the search transformations here: https://docs.kentico.com/k9/configuring-kentico/setting-up-search-on-your-website/displaying-search-results-using-transformations

How to use Watir to find a specific link when all the links have the same display text?

The links are wrapped in a span:
<span class='editbio'>
Edit
</span>
...
<span class='addbio'>
Edit
</span>
How about something like
browser.span(:class, "editbio").link(:text, "Edit")
to get the first link
vs
browser.span(:class, "addbio").link(:text, "Edit")
for the second link?
You can get a list of elements and tags you can use at Watir: Methods supported by Element.
You can try to use multiple arguments with the Watir's link method:
http://wiki.openqa.org/display/WTR/Multiple+Attributes
For your example, the accepted answer works fine. But if both of your links were in a single span and had the same display text, like so:
<span class='edit'>
Edit
Edit
</span>
You could use something like this for the second link (zero-based index):
browser.span(:class, 'edit').link(text: 'Edit', index: 1)

Resources