Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52523

Re: Getting a value that follows string.find()

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!panix!gordon
From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Getting a value that follows string.find()
Date Wed, 14 Aug 2013 15:58:02 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 28
Message-ID <kug9ea$267$1@reader1.panix.com> (permalink)
References <40816fed-38d4-4baa-92cc-c80cd8febd82@googlegroups.com>
NNTP-Posting-Host panix3.panix.com
X-Trace reader1.panix.com 1376495882 2247 166.84.1.3 (14 Aug 2013 15:58:02 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Wed, 14 Aug 2013 15:58:02 +0000 (UTC)
User-Agent nn/6.7.3
Xref csiph.com comp.lang.python:52523

Show key headers only | View raw


In <40816fed-38d4-4baa-92cc-c80cd8febd82@googlegroups.com> englishkevin110@gmail.com writes:

> I know the title doesn't make much sense, but I didnt know how to explain my problem.

> Anywho, I've opened a page's source in URLLIB
> starturlsource = starturlopen.read()
> string.find(starturlsource, '<a href="/profile.php?id=')
> And I used string.find to find a specific area in the page's source.
> I want to store what comes after ?id= in a variable.
> Can someone help me with this?

starturlsource = starturlopen.read()

match_string = '<a href="/profile.php?id='

match_index = string.find(starturlsource, match_string)

if match_index != -1:
    url = starturlsource[match_index + len(match_string):]

else:
    print 'not found'

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Getting a value that follows string.find() englishkevin110@gmail.com - 2013-08-13 15:51 -0700
  Re: Getting a value that follows string.find() Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-13 18:58 -0400
    Re: Getting a value that follows string.find() englishkevin110@gmail.com - 2013-08-13 16:03 -0700
      Re: Getting a value that follows string.find() Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-13 19:18 -0400
      Re: Getting a value that follows string.find() Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-13 19:40 -0400
      Re: Getting a value that follows string.find() Steven D'Aprano <steve@pearwood.info> - 2013-08-14 06:29 +0000
  Re: Getting a value that follows string.find() Dave Angel <davea@davea.name> - 2013-08-14 01:31 +0000
  Re: Getting a value that follows string.find() John Gordon <gordon@panix.com> - 2013-08-14 15:58 +0000

csiph-web