how to get an excerpt from a link

54 views
Skip to first unread message

sasogeek

unread,
Feb 1, 2013, 11:15:13 PM2/1/13
to web...@googlegroups.com
I want to do something similar to how facebook reatcs to links...
let's say a user makes a post with a link in it (the post is not necessarily just the link)
i want to be able to grab the link from the post, make it clickable, as well as a little excerpt from the contents in the page that link is anchored to.

eg.

blabla bla blablalbal bla blalba blalba crap! this is a link http://domain.com/somepage.html is a cool blog page.

when a user posts the above example, i want to make http://domain.com/somepage.html into an actual link which is clickable, as well as show some sort of excerpt from the contents in that page... i used fb as an example so it's easy to understand what i want to accomplish :)

help?

Massimo Di Pierro

unread,
Feb 2, 2013, 3:44:25 PM2/2/13
to web...@googlegroups.com
It depends. In which format is the input? markmin, html?

sasogeek

unread,
Feb 2, 2013, 7:49:23 PM2/2/13
to
Not sure if I understand your question but I guess I'll say html cos that's what I'm familiar with... :|

Massimo Di Pierro

unread,
Feb 2, 2013, 10:16:30 PM2/2/13
to web...@googlegroups.com
{{form gluon.contrib.autolinks import expand_html}}
{{=XML(expand_html(your_html),cache.ram('mycachekey',lambda:dict(),3600)}}

will do what you ask. Will expand all links not already tagged using the oembed protocol.


On Saturday, 2 February 2013 18:33:42 UTC-6, sasogeek wrote:
Not sure if I understand your question but I guess I'll say html cos that's what I'm familiar with... :|

On Saturday, 2 February 2013 20:44:25 UTC, Massimo Di Pierro wrote:

sasogeek

unread,
Feb 3, 2013, 6:40:59 PM2/3/13
to web...@googlegroups.com
Can i have an example of the full code... like replace your_html with an example code

Massimo Di Pierro

unread,
Feb 3, 2013, 7:02:17 PM2/3/13
to web...@googlegroups.com
{{extend 'layout.html'}}

{{html = """
Did you watch this video?<br/>

"""}}

{{form gluon.contrib.autolinks import expand_html}}
{{=XML(expand_html(your_html),cache.ram('mycachekey',lambda:dict(),3600)}}



sasogeek

unread,
Feb 3, 2013, 7:54:25 PM2/3/13
to web...@googlegroups.com

<type 'exceptions.RuntimeError'> Missing BeautifulSoup

Massimo Di Pierro

unread,
Feb 3, 2013, 8:09:12 PM2/3/13
to web...@googlegroups.com
Yes. I forgot.

Assuming you are running web2py from source you need to...

easy_install beautifulsoup

sasogeek

unread,
Feb 3, 2013, 9:40:05 PM2/3/13
to web...@googlegroups.com
Is installing beautiful soup all I need to do? cos I still get the same error after installing it...

Anthony

unread,
Feb 4, 2013, 1:48:06 AM2/4/13
to web...@googlegroups.com
Are you running web2py from source or using one of the binaries (the binaries include their own Python interpreter, so libraries installed in your local Python installation will not be available to web2py)?

Anthony
Reply all
Reply to author
Forward
0 new messages