Git Product home page Git Product logo

Comments (5)

rushter avatar rushter commented on May 29, 2024

It's a bug on my side. I will fix it. Thanks for the report.

from selectolax.

rushter avatar rushter commented on May 29, 2024

@Mancuerna You can try now, but you need to install selectolax from GitHub.

I will add some flexibility to the text functionality before releasing it to PyPi.

from selectolax.

Mancuerna avatar Mancuerna commented on May 29, 2024

I'm having the same problem with the latest fix. Here you have a Pastebin with the code I'm using to test it (sorry for not writing it here but Github's parser is messing it up).

https://pastebin.com/BB2KK6T3

As you can see the beautifulsoup4 print is the proper one while selectolax is only printing the text of the first element inside the div.

from selectolax.

rushter avatar rushter commented on May 29, 2024

Your second example is a bit different, that's why I wanted to add additional functionality.

In [1]: from selectolax.parser import HTMLParser

In [2]: html = '<div class="post-contents"> <p><a href="/testtest" rel="5" class="quote">#5</a> <a href="testtest" rel="2" class="quote">#2</a> <a href="testtest rel="4" class="qu
   ...: ote">#4</a> testtesttesttesttest.</p> </div>'
   ...: selector = "div.post-contents p"
   ...:

In [3]: for node in HTMLParser(html).css(selector):
   ...:     print(node.text(deep=False))
   ...:
   testtesttesttesttest.

In [4]: html = '<div class="post-contents"><p><strong><em>Night School Studio</em></strong>, estudio responsable de ' \
   ...:        '<em>Oxenfree</em> (una de las sorpresas del año pasado que pasó desapercibida tanto para prensa como ' \
   ...:        'comunidad), ha anunciado su próximo título, <strong><em>Afterparty</em></strong>.</p></div> '

In [5]:

In [5]: for node in HTMLParser(html).css("div.post-contents"):
   ...:     print(node.text())
   ...:
Night School Studio, estudio responsable de Oxenfree (una de las sorpresas del año pasado que pasó desapercibida tanto para prensa como comunidad), ha anunciado su próximo título, Afterparty.

I changed the behavior of text, now it's a function, not an attribute.
So, for the first example you need to use deep=False, otherwise, it will include all text from a tags.

Can you try now? Works for me.

from selectolax.

Mancuerna avatar Mancuerna commented on May 29, 2024

It works like a charm now. Thank you for your time <3

from selectolax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.