[Tutor] Getting value from web page

Kent Johnson kent37 at tds.net
Mon May 14 12:26:35 CEST 2007


Vladimir Strycek wrote:
> Hi all,
> 
> i have a page which when i download from web by python and put tu 
> variable have something like:
> 
>      <body>
>      
>      119/1157/43/40          
>      </body>
> 
> neer end ( actualy this is only thing on that page.... + <head stuff> )
> 
> What i need actualy is to get this values 119/1157/43/40 to 
> variables...., they are changing allthe time, but they stay numbers and 
> "/" is always between numbers, they are always 4
> 
> I tried using re to search for it but without luck :(
> 
> could somebody more experienced with re than me how to do it ?
> 
> something like match = re.match('+/',htmltxt)  (in htmltxt is the source 
> code downloaded from web)  <-- example not working ;)

You should use re.search(), not re.match() - match() only looks at the 
start of the text. Try
   match = re.search(r'(\d+)/(\d+)/(\d+)/(\d+)')

Then match.groups(1, 2, 3, 4) will be a tuple of the string 
representations of the numbers.

Kent


More information about the Tutor mailing list