SQL query to find columns with more than one string "a href" in them - mysql

I'm organizing articles in a big database and I face a problem - I need to find all articles with two or more links in them.
Every link is HTML link and has form .... How do I SELECT from article database with all links that a have at least two a href in them?
I was taught how to select one a href but two?...
SELECT * FROM `Articles5` WHERE
content LIKE "%a href%"
How to double this?

Had you tried using your own code but twice?
SELECT * FROM `Articles5` WHERE
content LIKE "%a href%a href%"

At first you can get all Articless WHERE content LIKE "%a href%" and put in temporary table. Then replace this value and find "a href" once more.
P.S For this purpose I advice you to use FullTextSearch

Related

Xpath with wildcards between id and divs?

I try to enter data in a table using Robot Framework. The table has an ID, but it changes every time I load the page (it is some kind of UUID) so I can't use it as "anchor" for my xpath. However there is a heading for this table that seems reasonable to start with that has a fixed ID. Inbetween the heading and the table there are a couple of divs. So something like this (some mix of pseudo code and what I get when I copy selector and xpath in Chrome) to get to the first cell in the first line of the table:
//*[#id="heading"] (a bunch of divs) /*[#id="random string of letters"]/div[3]/div/div/div[2]
I would like to write an xpath that looked something like this
//*[#id="heading"] [wildcard for the random ID and divs] /div[3]/div/div/div[2]
How do I write this?
Thank you.
If only one element inside the "header" contains an id attribute you could use
//*[#id="heading"]//*[#id]/div[3]/div/div/div[2]
If there are more than one element with id attribute you need something more, eg if it contains a certain tag
//*[#id="heading"]//*[contains(#id, "tag")]/div[3]/div/div/div[2]
or (if using xpath 2.0) and only this #id contains an uuid within the heading
//*[#id="heading"]//*[matches(#id,"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")]/div[3]/div/div/div[2]
Otherways you will have to try to find something unique (within the context of "heading") to start the div[3]/div/div/div[2] search (if you are lucky div[3]/div/div/div[2] is unique enough.

Remove different links from MySQL table

How i could remove different links i have in a MySQL field in many rows? I couldn't find a query for that.
I don't have much experience with MySQL, the ideal solutions would be something that begins with something and ends with something.
Example:
On table 'ads' i have a field called 'description' that has the ad description text. I have links inside the descriptions and i want to remove them all, but those links have different urls from ads to ads. I don't want to delete the text of the link, just the link itself <a class="something" href="http://someurl.com">Link text</a>
Please give a better explanation of your problem and a sample of code.
Although, if i'm right on what you want to achieve, you might need something like this below.
Example:
UPDATE ads SET description=REPLACE(description,'whatYouWantToDelete','')
The above will remove everything in your column that contains the string foo.
UPDATE:
These might be helpful.
Remove HTML tags from record
Removing links from posts in wordpress using query

REGEX in mysql table containing html data

I have a table that stores html templates in a mysql database. Now I have to perform some text replacement on them. However my target text is also present in some of the anchor tags and I don't want that to be replaced.
EX :
<body> ... (has huge html crap)... .........(Some more html crap) ... (a bit more of html crap) ... </body>
Task is to replace the occurrences of the "KEYWORD" with "NEW KEYWORD" in the body but not the urls.
It would also be helpful if I can first find such cases where the KEYWORD is a part of a link in a given template.
MySQL is not capable of such advanced string manipulation.
However, if you were to have a one-time-use PHP script do the editing (ie. select from the table, for each row process and update), you can do this:
// foreach row as $row
$newtext = preg_replace("(<a\b.*?>(*SKIP)(*FAIL)|KEYWORD)","NEW KEYWORD",$row['data']);
What this does is look for links (very approximate Regex but should suffice in almost all cases here), then skip over them. Then, it looks for KEYWORD and replaces it with NEW KEYWORD.
You can use this to quickly and easily handle the replacement.
If that "almost all cases" thing above turns out to not be enough, you can use DOMDocument to load the HTML into a parser and process text nodes only from there.
Maybe you could find the cases where the KEYWORD is a part of a link with something like this:
SELECT * FROM tbl WHERE html REGEXP '<a[^>]*KEYWORD';

Get Image with Xpath using class of Div

How do I write the xpath to get the main news image in this article?
The below one failed for me.
//div[contains(#class,'sectionColumns')]//div[contains(#class,'column2']//*img"]
I want it to return all images in case of slideshow. I want it to be flexible as some classes
change when news changes.
Without looking at "this article", there is an obvious syntax error in your XPath expression:
//div[contains(#class,'sectionColumns')]//div[contains(#class,'column2']//*img"]
The substring of the above:*img", contains two errors -- * followed by a name, and an unbalanced quote.
Probably you want:
//div[contains(#class,'sectionColumns')]//div[contains(#class,'column2']//img]

How to show related content using like in mysql?

I currently have a table for products with it's own set of tags and a table for news with it's own set of tags. I wanted to add related news to the products page so I was thinking of using like but since the column tags in the products page is something like
(Products) tags- manutd, man utd, football
(news) tags - manutd, blah, bruha [this one is related]
(news) tags - man, utd, bruha [this one is not related]
I wanted to use a query to show all news containing any of the tags(from products) seperated by commas using mysql. How should I go about constructing such a query? If there is a better way of doing this a little explanation would be helpful too. Thanks
Do you have the product tags at hand or do you want to join the two tables based on their tag similarity? In the first case, I would try something like this:
select ...
from News n
where n.tags REGEXP 'manutd|man utd|football'
Note that I used the product tag string you provided above, replaced the commas by | and removed the whitespace to the left and right of the commas.