473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Create a string array of all comments in a html file...

Hi, I'm wondering how i'd go about extracting a string array of all
comments in a HTML file, HTML comments obviously taking the format
"<!-- Comment text here -->".

I'm fairly stumped on how to do this? Maybe using regular expressions?

Thanks.

Sep 30 '07 #1
3 1982
On Sep 30, 10:39 am, sophie_newbie <paulgeele...@gmail.comwrote:
Hi, I'm wondering how i'd go about extracting a string array of all
comments in a HTML file, HTML comments obviously taking the format
"<!-- Comment text here -->".

I'm fairly stumped on how to do this? Maybe using regular expressions?

Thanks.
E:\Ruby>irb --prompt xmp
"<!-- Comment
here -->And <i>so</ifunny!
<p>It was a dark and stormy night.
</p><!-- Comment <-->".scan(/<!--.*?-->/m)
==>["<!-- Comment\nhere -->", "<!-- Comment <-->"]

Sep 30 '07 #2
On Sep 30, 10:39 am, sophie_newbie <paulgeele...@gmail.comwrote:
Hi, I'm wondering how i'd go about extracting a string array of all
comments in a HTML file, HTML comments obviously taking the format
"<!-- Comment text here -->".

I'm fairly stumped on how to do this? Maybe using regular expressions?

Thanks.
>>from pyparsing import htmlComment
htmlComment.searchString("""<!-- Comment
.... here -->And <i>so</ifunny!
.... </p><!-- Comment <-->""").asList()
[['<!-- Comment \nhere -->'], ['<!-- Comment <-->']]

-- Paul

Sep 30 '07 #3
sophie_newbie wrote:
Hi, I'm wondering how i'd go about extracting a string array of all
comments in a HTML file, HTML comments obviously taking the format
"<!-- Comment text here -->".

I'm fairly stumped on how to do this? Maybe using regular expressions?

from lxml import etree

parser = etree.HTMLParser()
tree = etree.parse("somefile.html", parser)

print tree.xpath("//comment()")
http://codespeak.net/lxml

Stefan
Oct 6 '07 #4

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

Similar topics

5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
2
by: Mriganka | last post by:
I want to create a hierarchical tree from the array of strings obtained by extracting a jar file.I want to do this using Javascript. For ex, I am having the entries in the array as...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I...
11
by: Tatu Portin | last post by:
Have this kind of struct: typedef struct { char **user_comments; /* ... */ } vorbis_comment; /* prototype */ char * read_vorbis_string ( FILE *sc);
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
6
by: Patient Guy | last post by:
I am a newcomer to using PHP but not to programming (C, C++, Javascript). I am playing around with classes and wanted to make a function that has a method simply for producing either plain text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.