skip to Main Content

I have a html file with many lines like this:

<div class="cell small-6 medium-4 large-3">
   <a href="/some-link/">
    <img src="some-image.jpg" alt="Bitter-Orange"> <br> Bitter Orange
  </a>
</div>

I want to remove all "a href" elements, get all images url’s and get all products names. Output must be like:

https://domainn.com/some-image.jpg/
Bitter Orange

I try with grep -o -E ‘https?://[^"]+’ and grep all links but how to delete them from file?

2

Answers


  1. How resolve this problem on word pressadmin login panal

    (Please check that the mysqli PHP extension is installed and enabled)

    Login or Signup to reply.
  2. If I understood correctly what you want, there are several ways to do this, see if this one fully meets your needs. Sorry about my English.

    If this is not what you want, let me know and I can help you using another approach.

    const divs = document.querySelectorAll('div.cell');
    for (let i = 0; i < divs.length; i++) {
      const div = divs[i];
      const img = div.querySelector('img');
      const name = div.querySelector('br').nextSibling.textContent.trim();
      console.log(`https://domainn.com/${img.getAttribute('src')} ${name}`);
      div.removeChild(div.querySelector('a'));
    }
    <!DOCTYPE html>
    <html>
    <head>
        <title>Exemplo</title>
    </head>
    <body>
        <div class="cell small-6 medium-4 large-3">
           <a href="/some-link/">
            <img src="some-image.jpg" alt="Bitter-Orange"> <br> Bitter Orange
          </a>
        </div>
    
        <div class="cell small-6 medium-4 large-3">
           <a href="/another-link/">
            <img src="another-image.jpg" alt="Sweet-Apple"> <br> Sweet Apple
          </a>
        </div>
        <div class="cell small-6 medium-4 large-3">
           <a href="/some-link/">
            <img src="some-image02.jpg" alt="Bitter-Orange02"> <br> Bitter Orange02
          </a>
        </div>
    
        <div class="cell small-6 medium-4 large-3">
           <a href="/another-link/">
            <img src="another-image02.jpg" alt="Sweet-Apple02"> <br> Sweet Apple02
          </a>
        </div>
        <div class="cell small-6 medium-4 large-3">
           <a href="/some-link/">
            <img src="some-image03.jpg" alt="Bitter-Orange03"> <br> Bitter Orange03
          </a>
        </div>
    
        <div class="cell small-6 medium-4 large-3">
           <a href="/another-link/">
            <img src="another-image03.jpg" alt="Sweet-Apple03"> <br> Sweet Apple03
          </a>
        </div>
    
        <script type="text/javascript">
            // código para obter imagens e nomes de produtos
        </script>
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search