Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28018
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: What do I do to read html files on my pc? |
| Date | 2012-08-28 17:38 +0200 |
| Organization | None |
| References | <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> <d356e2b9-62c4-4e5b-bc5a-63c3cb7a3685@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3900.1346168282.4697.python-list@python.org> (permalink) |
mikcec82 wrote:
> Il giorno lunedì 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto:
>> Hallo,
>>
>>
>>
>> I have an html file on my pc and I want to read it to extract some text.
>>
>> Can you help on which libs I have to use and how can I do it?
>>
>>
>>
>> thank you so much.
>>
>>
>>
>> Michele
>
> Hi Oscar,
> I tried as you said and I've developed the code as you will see.
> But, when I have a such situation in an html file, in wich there is a
> repetition of a string (XX in this case):
> CODE Target: 0201
> CODE Read: XXXX
> CODE CHECK : NOT PASSED
> TEXT Target: 13
> TEXT Read: XX
> TEXT CHECK : NOT PASSED
> CHAR Target: AA
> CHAR Read: XX
> CHAR CHECK : NOT PASSED
>
> With this code (created starting from yours)
>
> index = nomefile.find('XXXX')
> print 'XXXX_ found at location', index
>
> index2 = nomefile.find('XX')
> print 'XX_ found at location', index2
>
> found = nomefile.find('XX')
> while found > -1:
> print "XX found at location", found
> found = nomefile.find('XX', found+1)
>
> I have an answer like this:
>
> XXXX_ found at location 51315
> XX_ found at location 51315
> XX found at location 51315
> XX found at location 51316
> XX found at location 51317
> XX found at location 52321
> XX found at location 53328
>
> I have done it to find all occurences of 'XXXX' and 'XX' strings. But, as
> you can see, the script find the occurrences of XX also at locations
> 51315, 51316 , 51317 corresponding to string XXXX.
>
> Is there a way to search all occurences of XX avoiding XXXX location?
Remove the wrong positives afterwards:
start = nomefile.find("XX")
while start != -1:
if nomefile[start:start+4] == "XXXX":
start += 4
else:
print "XX found at location", start
start += 3
start = nomefile.find("XX", start)
By the way, what do you want to do if there are runs of "X" with repeats
other than 2 or 4?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What do I do to read html files on my pc? mikcec82 <michele.cecere@gmail.com> - 2012-08-27 03:59 -0700
Re: What do I do to read html files on my pc? Chris Angelico <rosuav@gmail.com> - 2012-08-27 21:58 +1000
Re: What do I do to read html files on my pc? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-27 13:05 +0100
Re: What do I do to read html files on my pc? mikcec82 <michele.cecere@gmail.com> - 2012-08-27 06:51 -0700
Re: What do I do to read html files on my pc? Joel Goldstick <joel.goldstick@gmail.com> - 2012-08-27 10:21 -0400
Re: What do I do to read html files on my pc? Chris Angelico <rosuav@gmail.com> - 2012-08-28 00:41 +1000
Re: What do I do to read html files on my pc? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-27 18:57 +0200
Re: What do I do to read html files on my pc? mikcec82 <michele.cecere@gmail.com> - 2012-08-28 03:09 -0700
Re: What do I do to read html files on my pc? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-08-28 13:31 +0100
Re: What do I do to read html files on my pc? Peter Otten <__peter__@web.de> - 2012-08-28 17:38 +0200
Re: What do I do to read html files on my pc? mikcec82 <michele.cecere@gmail.com> - 2012-08-29 03:22 -0700
Re: What do I do to read html files on my pc? Umesh Sharma <usharma01@gmail.com> - 2012-08-29 05:00 -0700
csiph-web