How to extract url from html page?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract url from html page?
# 15  
Old 10-16-2010
Do you have a sample url?
# 16  
Old 10-16-2010
Its just Google. Google is just an example.
# 17  
Old 10-16-2010
When I do wget www.google.com, I see no ▼-character.
# 18  
Old 10-17-2010
ok, the first time i do my test, i copied the html using the browser's view source. But since you mentioned wget, so here's how i do my next test. Using wget to download Google
Code:
$ wget 209.85.132.104

$ awk -F'>' '/^a href/{split($1,F,"\"");print F[2],$NF}' RS='<' index.html
http://mail.google.com/mail/?hl=en&tab=wm Gmail
http://www.google.com/intl/en/options/
/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg iGoogle
/preferences?hl=en Settings
https://www.google.com/accounts/Login?hl=en&continue=http://209.85.132.104/ Sign in
/advanced_search?hl=en Advanced Search
/language_tools?hl=en Language Tools
/intl/en/ads/ Advertising&nbsp;Programs
/services/ Business Solutions
/intl/en/about.html About Google
http://www.google.com/ncr Go to Google.com
/intl/en/privacy.html Privacy


$ ruby test.rb
-->http://www.google.com/imghp?hl=en&tab=wi, Images
-->http://video.google.com/?hl=en&tab=wv, Videos
-->http://maps.google.com/maps?hl=en&tab=wl, Maps
-->http://news.google.com/nwshp?hl=en&tab=wn, News
-->http://www.google.com/prdhp?hl=en&tab=wf, Shopping
-->http://mail.google.com/mail/?hl=en&tab=wm, Gmail
-->http://www.google.com/intl/en/options/, more »
-->/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg, iGoogle
-->/preferences?hl=en, Settings
-->https://www.google.com/accounts/Login?hl=en&continue=http://209.85.132.104/, Sign in
-->/advanced_search?hl=en, Advanced Search
-->/language_tools?hl=en, Language Tools
-->/intl/en/ads/, Advertising*Programs
-->/services/, Business Solutions
-->/intl/en/about.html, About Google
-->http://www.google.com/ncr, Go to Google.com
-->/intl/en/privacy.html, Privacy

If you notice at Google main page, there is a link called "more" right at the top, and the down arrow key is next to it, which is reflected in the ruby output as
Code:
-->http://www.google.com/intl/en/options/, more »

The down arrow key is itself a url link.
This User Gave Thanks to kurumi For This Post:
# 19  
Old 10-17-2010
Thanks Kurumi, it was because of event definitions in the tag.
Code:
awk -F'>' '/[ \t]href=/{N=split($1,F,"\""); i=1; while(F[i++]!~/[ \t]href=/); print F[i],$NF}' RS='<'

This User Gave Thanks to Scrutinizer For This Post:
# 20  
Old 10-17-2010
thanks scrutinizer for following up on this. you are almost there. Smilie
Code:
$ awk -F'>' '/[ \t]href=/{N=split($1,F,"\""); i=1; while(F[i++]!~/[ \t]href=/); print F[i],$NF}' RS='<' index.html |sort
/advanced_search?hl=en Advanced Search
http://mail.google.com/mail/?hl=en&tab=wm Gmail
http://maps.google.com/maps?hl=en&tab=wl Maps
http://news.google.com/nwshp?hl=en&tab=wn News
https://www.google.com/accounts/Login?hl=en&continue=http://209.85.132.104/ Sign in
http://video.google.com/?hl=en&tab=wv Videos
http://www.google.com/imghp?hl=en&tab=wi Images
http://www.google.com/intl/en/options/
http://www.google.com/ncr Go to Google.com
http://www.google.com/prdhp?hl=en&tab=wf Shopping
/intl/en/about.html About Google
/intl/en/ads/ Advertising&nbsp;Programs
/intl/en/privacy.html Privacy
/language_tools?hl=en Language Tools
/preferences?hl=en Settings
/services/ Business Solutions
/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg iGoogle

$ ruby test.rb index.html |sort
-->/advanced_search?hl=en, Advanced Search
-->http://mail.google.com/mail/?hl=en&tab=wm, Gmail
-->http://maps.google.com/maps?hl=en&tab=wl, Maps
-->http://news.google.com/nwshp?hl=en&tab=wn, News
-->https://www.google.com/accounts/Login?hl=en&continue=http://209.85.132.104/, Sign in
-->http://video.google.com/?hl=en&tab=wv, Videos
-->http://www.google.com/imghp?hl=en&tab=wi, Images
-->http://www.google.com/intl/en/options/, more »
-->http://www.google.com/ncr, Go to Google.com
-->http://www.google.com/prdhp?hl=en&tab=wf, Shopping
-->/intl/en/about.html, About Google
-->/intl/en/ads/, Advertising*Programs
-->/intl/en/privacy.html, Privacy
-->/language_tools?hl=en, Language Tools
-->/preferences?hl=en, Settings
-->/services/, Business Solutions
-->/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg, iGoogle

# 21  
Old 10-17-2010
This because there are underline tags with angular brackets in the description. I give up without a library Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Page Not Found error while parsing url

Hi I just tried to post following link while answering, its not parsing properly, just try on your browser Tried to paste while answering : https://www.unix.com/302873559-post2.htmlNot operator is not coming with HTML/PHP tags so attaching file (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. Shell Programming and Scripting

Use curl to send a static xml file using url encoding to a web page using pos

Hi I am try to use curl to send a static xml file using url encoding to a web page using post. This has to go through a particular port on our firewall as well. This is my first exposure to curl and am not having much success, so any help you can supply, or point me in the right direction would be... (1 Reply)
Discussion started by: Paul Walker
1 Replies

3. Shell Programming and Scripting

URL/HTML encoding

Hey guys, looking for a way to encode a string into URL and HTML in a bash script that I'm making to encode strings in various different digests etc. Can't find anything on it anywhere else on the forums. Any help much appreciated, still very new to bash and programming etc. (4 Replies)
Discussion started by: 3therk1ll
4 Replies

4. Shell Programming and Scripting

Extracting anchor text and its URL from HTML files in BASH

Hi All, I have some HTML files and my requirement is to extract all the anchor text words from the HTML files along with their URLs and store the result in a separate text file separated by space. For example, <a href="/kid/stay_healthy/">Staying Healthy</a> which has /kid/stay_healthy/ as... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Red Hat

Publishing HTML Page

Hi All, Thanks for reading. I am not sure if I am asking this in the correct group. But here it goes: There is a shell script which does some system checks and creates an html file called system_summary.html on my Red Hat machine say in /reports directory every hour. Now I want to view it... (6 Replies)
Discussion started by: deepakgang
6 Replies

6. UNIX for Dummies Questions & Answers

Publishing HTML Page

Hi All, Thanks for reading. I am not sure if I am asking this in the correct group. But here it goes: There is a shell script which does some system checks and creates an html file called system_summary.html on my Red Hat machine say in /reports directory every hour. Now I want to view it... (1 Reply)
Discussion started by: deepakgang
1 Replies

7. Web Development

findstr in html page

I am planning to create an html page that will count number of connected ports, challenge for me is how to put it in a page. Thanks! (1 Reply)
Discussion started by: webmunkey23
1 Replies

8. Solaris

Accessing a HTML page

Hi All, In our unix server we have an apache web server running. I can access the default apache web page from my windows machine. Now, I want to create my own webpage. Therefore I created webpage at /export/home/myname/test.html file. Where do I need to place this file and what do I need... (0 Replies)
Discussion started by: pkm_oec
0 Replies

9. UNIX for Dummies Questions & Answers

How do I extract text only from html file without HTML tag

I have a html file called myfile. If I simply put "cat myfile.html" in UNIX, it shows all the html tags like <a href=r/26><img src="http://www>. But I want to extract only text part. Same problem happens in "type" command in MS-DOS. I know you can do it by opening it in Internet Explorer,... (4 Replies)
Discussion started by: los111
4 Replies

10. Shell Programming and Scripting

How to get the page size (of a url) using wget

Hi , I am trying to get page size of a url(e.g.,www.example.com) using wget command.Any thoughts what are the parameters i need to send with wget to get the size alone? Regards, Raj (1 Reply)
Discussion started by: rajbal
1 Replies
Login or Register to Ask a Question