help with sed needed to extract content from html tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with sed needed to extract content from html tags
# 1  
Old 03-04-2012
help with sed needed to extract content from html tags

Hi
I've searched for it for few hours now and i can't seem to find anything working like i want. I've got webpage, saved in file par with form like this:
Code:
<html><body><form name='sendme' action='http://example.com/' method='POST'>
<textarea name='1st'>abc123def678</textarea>
<textarea name='2nd'>Text</textarea>
<textarea name='3rd'>Text</textarea>
</form></body></html>

and I want to extract content from textarea tags

Code:
cat par | sed -e 's/.*1st//' -e 's/<\/textarea>.*//'

wchich returns
Code:
'>abc123def678

i can't seem to be able to get rid of the '>, can anyone recommend me a working solution with sed ?
# 2  
Old 03-04-2012
Code:
sed '/1st/ s:<textarea[^>]*>\([^<]*\)</textarea>:\1:;q' par

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 03-04-2012
that returns

Code:
<html><body><form name='sendme' action='http://example.com/' method='POST'>
abc123def678
<textarea name='2nd'>Text</textarea>
<textarea name='3rd'>Text</textarea>
</form></body></html>

i've tried

Code:
sed '/1st/ s:<textarea[^>]*>\([^<]*\)</textarea>.*:\1:;q' par

with result
Code:
<html><body><form name='sendme' action='http://example.com/' method='POST'>
abc123def678

Code:
sed '/1st/ s:.*<textarea[^>]*>\([^<]*\)</textarea>.*:\1:;q' par

returns last textarea with text

any idea how to modify it ?
# 4  
Old 03-04-2012
AttributeError: 'module' object has no attribute 'logger

hi all, when installing sage, there is a problem with emacs.py
so, this screen appeared after rynning ./sage
----------------------------------------------------------------------
| Sage Version 4.4.2, Release Date: 2010-05-19 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/zid/sage/local/bin/sage-ipython", line 18, in <module>
import IPython
File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line
58, in <module>
__import__(name,glob,loc,[])
File "/usr/lib/python2.7/dist-packages/IPython/ipstruct.py", line
17, in <module>
from IPython.genutils import list2dict2
File "/usr/lib/python2.7/dist-packages/IPython/genutils.py", line
114, in <module>
import IPython.rlineimpl as readline
File "/usr/lib/python2.7/dist-packages/IPython/rlineimpl.py", line
18, in <module>
from pyreadline import *
File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1-
py2.7.egg/pyreadline/__init__.py", line 11, in <module>
from . import unicode_helper, logger, clipboard, lineeditor,
modes, console
File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1-
py2.7.egg/pyreadline/modes/__init__.py", line 3, in <module>
from . import emacs, notemacs, vi
File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1-
py2.7.egg/pyreadline/modes/emacs.py", line 11, in <module>
import pyreadline.logger as logger
AttributeError: 'module' object has no attribute 'logger'
any one can help me pleaseeee

regards
Zid
# 5  
Old 03-04-2012
Code:
sed -n '/textarea/p' infile | sed -e 's/<[^>]*>//g'

gives
Code:
abc123def678
Text
Text

This User Gave Thanks to fpmurphy For This Post:
# 6  
Old 03-05-2012
Or this..?
Code:
sed -n '/text/s/<[^<]*>//gp' inputfile
sed -n '/text.*1st/s/<[^<]*>//gp' inputfile


Last edited by michaelrozar17; 03-05-2012 at 02:03 AM.. Reason: alternate sed solution..
This User Gave Thanks to michaelrozar17 For This Post:
# 7  
Old 03-05-2012
still not there, both (fpmurphy, michaelrozar17) return same result
everything in between all html brackets
Code:
abc123def678TextText

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk/sed HTML extract

I'm extracting text between table tags in HTML <th><a href="/wiki/Buick_LeSabre" title="Buick LeSabre">Buick LeSabre</a></th> using this: awk -F "</*th>" '/<\/*th>/ {print $2}' auto2 > auto3 then this (text between a href): sed -e 's/\(<*>\)//g' auto3 > auto4 How to shorten this into one... (8 Replies)
Discussion started by: p1ne
8 Replies

2. Shell Programming and Scripting

Print content between two html tags

Hi Expert, Is there any other way to print and write to a same filename the content between two html tags? Here the sample: cat file.html <div id="outline"> hello world<br> </div> <div id="container_faq"> test1<br> </div> <div class="widget_quick"> thead test<br> </div> ... (3 Replies)
Discussion started by: lxdorney
3 Replies

3. UNIX for Dummies Questions & Answers

Replacing HTML tags with sed

Ok, so this is stupid simple, and I know I am going to feel like an idiot when I get help. I am altering a HTML report that has contraband in it so that the links to said contraband and the images are not shown. The link/img pairs are in the form of : <a... (5 Replies)
Discussion started by: twjolson
5 Replies

4. Shell Programming and Scripting

awk -- Extract data from html within multiple tags as reference

Hi, I'm trying to get some data from an html file, but the problem is before it can extract the information I have multiple patterns that need to be passed through. https://www.unix.com/shell-programming-scripting/150711-extract-data-awk-html-files.html Is a similar problem. The only... (5 Replies)
Discussion started by: counfhou
5 Replies

5. Shell Programming and Scripting

SED to extract HTML text data, not quite right!

I am attempting to extract weather data from the following website, but for the Victoria area only: Text Forecasts - Environment Canada I use this: sed -n "/Greater Victoria./,/Fraser Valley./p" But that phrasing does not sometimes get it all and think perhaps the website has more... (2 Replies)
Discussion started by: lagagnon
2 Replies

6. Shell Programming and Scripting

sed - striping out html tags

I have pasted the contents of a log file (swmbackup.wrkstn.1262071383.sales2a) below: Workstation: sales2a<BR Vault sales2a-hogwarts will be initialized.<BR <font color="red"There was a problem mounting /mnt/sales2a/desktop$ </FONT<BR <font color="red"There was a problem mounting... (4 Replies)
Discussion started by: bigtonydallas
4 Replies

7. Shell Programming and Scripting

Extract URLs from HTML code using sed

Hello, i try to extract urls from google-search-results, but i have problem with sed filtering of html-code. what i wont is just list of urls thay apears between ........<p><a href=" and next following " in html code. here is my code, i use wget and pipelines to filtering. wget works, but... (13 Replies)
Discussion started by: L0rd
13 Replies

8. Shell Programming and Scripting

sed to extract only floating point numbers from HTML

Hi All, I'm trying to extract some floating point numbers from within some HTML code like this: <TR><TD class='awrc'>Parse CPU to Parse Elapsd %:</TD><TD ALIGN='right' class='awrc'> 64.50</TD><TD class='awrc'>% Non-Parse CPU:</TD><TD ALIGN='right' class='awrc'> ... (2 Replies)
Discussion started by: pondlife
2 Replies

9. UNIX for Advanced & Expert Users

sed to extract HTML content

Hiya, I am trying to extract a news article from a web page. The sed I have written brings back a lot of Javascript code and sometimes advertisments too. Can anyone please help with this one ??? I need to fix this sed so it picks up the article ONLY (don't worry about the title or date .. i got... (2 Replies)
Discussion started by: stargazerr
2 Replies

10. Shell Programming and Scripting

How to supplement HTML tags with SED

I am cleaning up HTML with sed. With the regexp <a name="+"></a><h>*<span class="mw-headline" >+</span></h> I can find the tags I need. But when I place them in a sed command, sed fails. So I started building up from a smaller command. This is where I am now: sed -r -e s/"<a... (3 Replies)
Discussion started by: DocBrewer
3 Replies
Login or Register to Ask a Question