get the text matching a tag inside

regular expression for anchor tag in javascript
regex extract href from anchor tag
beautifulsoup get text inside tag
regex get text between tags javascript
regex get tags
get text inside p tag python
beautifulsoup get text from website
beautifulsoup get text in tag

Im totally lost to get this ! It's frustrating, I need your help

Im looking to get text who appear after h2 id="coucou10" inside a div who have same classes

exemple

the code:

<div class="sameclass">blablabla</div>

<div class="sameclass"> 
  <h2 id="coucou10">Coucou</h2>
  blablabla 2 html to <br> 
  select this is the text I want<br>
  blabla bla bla bal balbal blabla
</div>

<div class="sameclass">
  <h2 id="coucou20">Coucou</h2>
  blablabla
</div>

Here is a possible solution. The content is filtert for TEXT_NODE. You don not get the <br> element.

console.log("Text of element with id(coucou10): " + $('div.sameclass #coucou10').contents().filter(function() {
  return this.nodeType == Node.TEXT_NODE;}).text()
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sameclass">blablabla</div>

<div class="sameclass"> 
  <h2 id="coucou10">Coucou</h2>
  blablabla 2 html to <br> 
  select this is the text I want<br>
  blabla bla bla bal balbal blabla
</div>

<div class="sameclass">
  <h2 id="coucou20">Coucou</h2>
  okeydokey
</div>

Match html tag, RegEx for matches tag and text inside it. Hello world · find apostrophe · VietNam Mobile Phone Regex by Javascript · URL (with localhost) · nhl scoreboard test As usual with groups, place your regex definitions inside grouping parentheses so you can extract the actual text that matches your regex patterns from the String. In the following source code example I demonstrate how to extract the text between the opening and closing HTML code tags from a given multi-line String:

javascript solution...

        var allItems = document.getElementsByClassName('sameclass');
        for(var i=0; i < allItems.length; i++){
            for(var k=0; k < allItems[i].children.length; k++){
                if (allItems[i].children[k].localName == 'h2'){
                    var resettingZero = i + 1;
                    console.log("'sameclass' occurance# "+resettingZero+", we got h2 with the value:" + allItems[i].children[k].innerHTML);
                }
            }

        }
    
    <div class="sameclass">blablabla</div>

    <div class="sameclass"> 
    <h2 id="coucou10">Coucou</h2>
    blablabla 2 html to <br> 
    select this is the text I want<br>
    blabla bla bla bal balbal blabla
    </div>

    <div class="sameclass">
    <h2 id="coucou20">Coucou</h2>
    blablabla
    </div>

Rapid Web Applications with TurboGears: Using Python to Create , To make scanning and manipulating the original contents of the matching tag as In the preceding code, we are using the text attribute of an element to return  In Sublime Text or any other code editor you can use regular expressions to get rid of unwanted tags, classes and even attributes. Just open the search bar (CTRL+F), make sure to select the icon with a dot and asterisk (.*) which means "Enable Regular Expressions" , then you can find and replace regex html tag or attribute.

You Can use the below mentioned snippet to get the output above. If you having many elements having class '.sameclass > #coucou10' you can utilize for loops and execute the required values

document.querySelectorAll('.sameclass > #coucou10')[0].parentElement.childNodes.forEach(function(e){if(e.nodeType === 3 && e.textContent.trim().length != 0)console.log(e.textContent.trim())})
<div class="sameclass">blablabla</div>

<div class="sameclass"> 
  <h2 id="coucou10">Coucou</h2>
  blablabla 2 html to <br> 
  select this is the text I want<br>
  blabla bla bla bal balbal blabla
</div>

<div class=">sameclass<">
  <h2 id="coucou20">Coucou</h2>
  blablabla
</div>

A JavaScript function to extract text from an anchor tag (using a , A JavaScript function to extract text from an anchor tag (using a regex) The regular expression in the match method does the dirty work. I find it hard to explain regular expressions, but the important part is that I extract the  Beautifulsoup text from tags inside of tags Hot Network Questions When it comes to verbs on action buttons on a user interface, why is the infinitive verb often used instead of a command form of the verb?

Some vanilla JS:

// grab the element with the coucou10 id
const p = document.getElementById('coucou10');

// find its parent node, and then all the childNodes
// make sure they're iterable
const txt = [...p.parentNode.childNodes]

      // filter out elements that aren't text nodes
      .filter(node => node.nodeName === '#text')

      // grab the text content from those nodes
      .map(node => node.textContent.trim())

      // filter out the empty strings
      .filter(txt => txt !== '')

      // join the array of strings
      // (i've used a line break here but remove/add a space instead
      // according to your needs)
      .join('\n');
      
console.log(txt);
<div class="sameclass">blablabla</div>

<div class="sameclass"> 
  <h2 id="coucou10">Coucou</h2>
  <p>d</p>
  blablabla 2 html to <br> 
  select this is the text I want<br>
  blabla bla bla bal balbal blabla
</div>

<div class="sameclass">
  <h2 id="coucou20">Coucou</h2>
  blablabla
</div>

How the Tag Finder Works, In this property, you can specify where to find the tag relative to a named tag. "​Equals Text" specifies that the attribute value must match a specified text. Some tasks require you to extract text from HTML, especially in web scraping. one popular solution is to use the HtmlAgilityPack-DocumentNode.InnerText-, however this requiring you add an extra library to your project, and have drawbacks in some edge cases.

13. How to get text from web pages, While the task of finding tags in a page seems simple enough, so many things can but to look carefully at the HTML to find the tag that contains text and extract it the largest match, which is the entire pattern. group(1) returns the next match,  Returns XmlNodeList. An XmlNodeList containing a list of all matching nodes. If no nodes match name, the returned collection will be empty.. Examples. The following example creates a XmlDocument object and uses the GetElementsByTagName method and the resulting XmlNodeList object to display all the book titles.

match() \ Language (API) \ Processing 3+, match(). Examples. String s = "Inside a tag, you will find but the sequence matches, an array of length 1 (with the matched text as the first  Also we can use jquery val () method inside script to get or set the value of text input field. Example-1: This example uses Text value property to get the value from input text field. field, and then click the button below. The val () method is used to return or set the value attribute of the selected elements.

:contains() Selector, The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value  The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue; A visited link is underlined and purple

Comments
  • What if there is no heading? Ignore it? Also, what have you tried? You might find reading the site help section useful when it comes to asking a good question. Without code your question is unclear - a minimal reproducible example will help. Here's a question checklist you might find useful..
  • ok thanks but I need the text from id= coucou10, not all of the same class
  • oh okey so i missunderstood you. I edited my solution for you.