Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > BeautifulSoup

Reply
Thread Tools

BeautifulSoup

 
 
elsa
Guest
Posts: n/a
 
      09-02-2009
Hi all,

if I have some HTML that looks like this:

<area coords="427,724,432,732" href="http://BioCyc.org/ECOLI/NEW-IMAGE?
type=GENE-IN-CHROM-BROWSER&amp;object=EG12309" onmouseover="return
overlib('&lt;b&gt;Gene:&lt;/b&gt; yjtD&lt;BR&gt;&lt;b&gt;Product:&lt;/
b&gt; predicted rRNA methyltransferase, subunit of predicted rRNA
methyltransferase&lt;BR&gt;&lt;b&gt;Intergenic distances (bp):&lt;/
b&gt; yjjY&lt; +400 yjtD +214 &gt;thrL');"><b>Gene:</b> yjtD<br /
><b>Product:</b> predicted rRNA methyltransferase, subunit of

predicted rRNA methyltransferase<br /><b>Intergenic distances (bp):</
b> yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
</area>

is there an easy way to use BeautifulSoup to extract just the value of
the href attribute?

Thanks,

elsa
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      09-02-2009
elsa wrote:

> if I have some HTML that looks like this:
>
> <area coords="427,724,432,732" href="http://BioCyc.org/ECOLI/NEW-IMAGE?
> type=GENE-IN-CHROM-BROWSER&amp;object=EG12309" onmouseover="return
> overlib('&lt;b&gt;Gene:&lt;/b&gt; yjtD&lt;BR&gt;&lt;b&gt;Product:&lt;/
> b&gt; predicted rRNA methyltransferase, subunit of predicted rRNA
> methyltransferase&lt;BR&gt;&lt;b&gt;Intergenic distances (bp):&lt;/
> b&gt; yjjY&lt; +400 yjtD +214 &gt;thrL');"><b>Gene:</b> yjtD<br /
>><b>Product:</b> predicted rRNA methyltransferase, subunit of

> predicted rRNA methyltransferase<br /><b>Intergenic distances (bp):</
> b> yjjY< +400 yjtD +214 >thrL');" onmouseout="return nd();">
> </area>
>
> is there an easy way to use BeautifulSoup to extract just the value of
> the href attribute?


>>> from BeautifulSoup import BeautifulSoup as BS
>>> html = "<area ..."
>>> BS(html).find("area")["href"]

u'http://BioCyc.org/ECOLI/NEW-IMAGE?\ntype=GENE-IN-CHROM-
BROWSER&object=EG12309'


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
scraping nested tables with BeautifulSoup Gonzillaaa@gmail.com Python 7 04-04-2006 05:21 PM
how to run BeautifulSoup in Jython ye juan Python 1 02-05-2006 09:28 AM
BeautifulSoup fetch help ted Python 2 01-07-2006 06:11 AM
BeautifulSoup Steve Young Python 4 08-20-2005 06:47 AM
HTML purifier using BeautifulSoup? Dan Stromberg Python 1 01-07-2005 06:10 PM



Advertisments