473,761 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract headlines from a HTML file.

Hi everyone,

I try to write a simple web crawler. It has to do the following:
1) Open an URL and retrieve a HTML file.
2) Extract news headlines from the HTML file
3) Put the headlines into a RSS file.

For example, I want to go to this site and extract the headlines:
www.unstrung.com/section.asp?section_id=86

The problem is I do not know howto extract a headline from a HTML
file.
I mean HTML is not structured as XML, so I do not really know to solve
this problem. I notice that PHP has URL Functions to deal with HTML
file. For example, you have get_meta_tags () to extract meta tag
content attributes from a HTML file. But then, extract meta tag is
easy. With headlines, I don't really know where the headlines are on
a HTML file. Would anyone give me inputs on this?

This is not an impossible problem. If you look at Google News
(http://news.google.com/), they crawl the web and sort the headlines
on their site.

Thanks,
P. Ho
Jul 17 '05 #1
3 3924
On 3 Aug 2004 14:24:11 -0700, pe********@yaho o.com (Phong Ho) wrote:
I try to write a simple web crawler. It has to do the following:
1) Open an URL and retrieve a HTML file.
2) Extract news headlines from the HTML file
3) Put the headlines into a RSS file.

For example, I want to go to this site and extract the headlines:
www.unstrung.com/section.asp?section_id=86

The problem is I do not know howto extract a headline from a HTML
file.
I mean HTML is not structured as XML, so I do not really know to solve
this problem. I notice that PHP has URL Functions to deal with HTML
file. For example, you have get_meta_tags () to extract meta tag
content attributes from a HTML file. But then, extract meta tag is
easy. With headlines, I don't really know where the headlines are on
a HTML file. Would anyone give me inputs on this?

This is not an impossible problem. If you look at Google News
(http://news.google.com/), they crawl the web and sort the headlines
on their site.


Whilst entirely possible in PHP, I'd use Perl for this, as there are many
extremely useful modules for this sort of thing. HTML::TableExtr act,
HTML::Parser, WWW::Mechanize to name a few.

But make sure you're not infringing on their copyright by redistributing the
extracted headlines.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
(v1.4.0 new 1st Aug 2004)
Jul 17 '05 #2
"Andy Hassall" wrote:
On 3 Aug 2004 14:24:11 -0700, pe********@yaho o.com (Phong Ho) wrote:
I try to write a simple web crawler. It has to do the following:
1) Open an URL and retrieve a HTML file.
2) Extract news headlines from the HTML file
3) Put the headlines into a RSS file.

For example, I want to go to this site and extract the headlines:
www.unstrung.com/section.asp?section_id=86

The problem is I do not know howto extract a headline from a HTML
file.
I mean HTML is not structured as XML, so I do not really know to solve
this problem. I notice that PHP has URL Functions to deal with HTMLfile. For example, you have get_meta_tags () to extract meta tag
content attributes from a HTML file. But then, extract meta tag iseasy. With headlines, I don’t really know where the headlines

are on
a HTML file. Would anyone give me inputs on this?

This is not an impossible problem. If you look at Google News
(http://news.google.com/), they crawl the web and sort the headlines
on their site.


Whilst entirely possible in PHP, I’d use Perl for this, as
there are many
extremely useful modules for this sort of thing.

HTML::TableExtr act, HTML::Parser, WWW::Mechanize to name a few.

But make sure you’re not infringing on their copyright by
redistributing the
extracted headlines.


Or do it the brute force way, using regular expressions. Just refer
to the manul for doing that. I don’t think php as well developed
modules for doing this (vs. Perl) but I could be wrong.

If you know regular expressions, this is an easy thing to do, by the
way.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Extract-...ict136182.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=454893
Jul 17 '05 #3
I do not have experience with Perl but I would like to ask a question
concerning Perl. I will use web hosting from a web hosting company,they
support Perl(CGI-BIN) but I won't have the root account. Do you need a
root account to install a Perl Module?

Also, anyone know if there is a sample in PHP to extract the headlines
from a HTML file on the internet?

Thanks

steve wrote:
"Andy Hassall" wrote:
> On 3 Aug 2004 14:24:11 -0700, pe********@yaho o.com (Phong Ho) wrote:
>
> >I try to write a simple web crawler. It has to do the following:
> >1) Open an URL and retrieve a HTML file.
> >2) Extract news headlines from the HTML file
> >3) Put the headlines into a RSS file.
> >
> >For example, I want to go to this site and extract the headlines:
> >www.unstrung.com/section.asp?section_id=86
> >
> >The problem is I do not know howto extract a headline from a HTML
> >file.
> >I mean HTML is not structured as XML, so I do not really know to

> solve
> >this problem. I notice that PHP has URL Functions to deal with HTML > >file. For example, you have get_meta_tags () to extract meta tag
> >content attributes from a HTML file. But then, extract meta tag is > >easy. With headlines, I don’t really know where the headlines

> are on
> >a HTML file. Would anyone give me inputs on this?
> >
> >This is not an impossible problem. If you look at Google News
> >(http://news.google.com/), they crawl the web and sort the headlines
> >on their site.

>
> Whilst entirely possible in PHP, I’d use Perl for this, as
> there are many
> extremely useful modules for this sort of thing.

HTML::TableExtr act,
> HTML::Parser, WWW::Mechanize to name a few.
>
> But make sure you’re not infringing on their copyright by
> redistributing the
> extracted headlines.
>


Or do it the brute force way, using regular expressions. Just refer
to the manul for doing that. I don’t think php as well developed
modules for doing this (vs. Perl) but I could be wrong.

If you know regular expressions, this is an easy thing to do, by the
way.


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6918
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the file name. I can successfully extract the TITLE section, but no luck with the AUTHOR part. Any idea why?
3
6002
by: Joe | last post by:
I'm trying to extract part of html code from a tag to a tag code begins with <span class="boldyellow"><B><U> and ends with TD><TD> <img src="http://whatever/some.gif"> </TD></TR></TABLE> I was thinking of using a regular expression however I having hard time getting the desired string. I use htmlSource = urllib.urlopen("http://address/") s = htmlSource.read() htmlSource.close()
6
2224
by: Selen | last post by:
I would like to be able to extract a BLOB from the database (SqlServer) and pass it to a browser without writing it to a file. (The BLOB's are word doc's, MS project doc's, and Excel spreadsheets. How can I do this?
0
1625
by: Vjay77 | last post by:
I posted this question, but I pressed 'post' and it disappeared. So once again: Problem: I need to go to lets say www.site.com/page.html Imagine that this html code is 6 mb long. I need to extract information between bytes 5000 and 5020.
9
7308
by: trihanhcie | last post by:
Hi, I would like to extract the text in an HTML file For the moment, I'm trying to get all text between <tdand </td>. I used a regular expression because i don't know the "format between <tdand </td> It can be : <tdtext1 </td> or
1
3667
by: steveyjg | last post by:
I want to extract the following data from a retrieved html file and store the information as strings. 'get the text of "title" <h1 id="test_title">title</h1> 'get the contents of the value attribute <input name="test_code" type="text" value='<object </object>' > 'get the text of "category" or value of c <div class="smallText">
1
3664
by: nkg1234567 | last post by:
I'm trying to extract HTML from a website in the form of a string, and then I want to extract particular elements from the string using the substr function: here is some sample code that I have thus far: use HTTP::Request::Common; use LWP::UserAgent; use LWP::Simple; $ua = LWP::UserAgent->new;
1
3070
by: veer | last post by:
Hi i am making a program in which i want to extract data from html file . Actually there are two dates on html file i want to extract these dates but the main probleum is that these dates are different on each file. A word "AKTIVA" is always comes before these dates. i made this by seaching the activa word but after this i am not getting any idea how these dates can be accessed. i use one another method by transfering the whole data of...
3
4104
rizwan6feb
by: rizwan6feb | last post by:
I am trying to extract php code from a php file (php file also contains html, css and javascript code). I am using the following regex for this <\?*?\?> but this doesn't cater quotation marks (single and double quotes) and comments, i mean how can i skip php tags inside a string (and comments). Please have a look at the following code <?php include("db.php"); $name=$_REQUEST;
0
9538
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.