-1

I'm trying to read a number from a website into a variable. The source code where the number is looks like this:

<tr bgcolor="#ccffff"><td>N_300_0</td><td>5918.720</td></tr>

The website will always say N_300_0 but the number will change.

So far I have:

link = urllib2.urlopen("http://www.example.com").read()
matches = re.findall('N_300_0', link);
number = ....

How do I get the number into the variable?

3

1 Answer 1

0

If you are doing any serious or involved scraping, I would strongly agree that something like BeautifulSoup is a much better way to go.

But to answer your question, you need to use grouping in python regex via parens to do the sort of capturing you want, e.g.

numbers = re.findall('N_300_0</td><td>([-+]?\d*\.\d+|\d+)',s)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.