omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    BeautifulSoup different behavior in Pythonista?

    Pythonista
    2
    3
    2001
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rmanly
      rmanly last edited by

      Can anyone help me to understand why this works in OS X but not in Pythonista?

      https://gist.github.com/rmanly/7648823

      For those who do not want to be bothered to click the link it is only 4 lines of code...7 with the imports. ;)

      Also, on the interactive console in Pythonista why do things like 'soup.p', 'soup.a' etc. not work.

      1 Reply Last reply Reply Quote 0
      • RainmanNoodles
        RainmanNoodles last edited by

        Weird. I think it may be a bug. ALSO: it's not fixed by Pythonista 1.4.

        In the meantime, try this:

        import requests
        import webbrowser
        import re
        
        page = requests.get('http://xkcd.com')
        comic = re.search("http://imgs.xkcd.com/comics/[^\.]*.png",page.text).group()
        webbrowser.open(comic)
        

        You can even snag the alt text:

        alt = re.search('src="http://imgs.xkcd.com/comics/[^\.]*.png"\s*title="([^"]*)"\s*alt=',page.text).groups()[0]
        
        1 Reply Last reply Reply Quote 0
        • rmanly
          rmanly last edited by

          Hrmmm...

          Thanks for the response.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors