-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?

h_user
  • 113
  • 1
  • 5
  • 1
    Try using beautifulsoup: http://www.crummy.com/software/BeautifulSoup/ – Reut Sharabani Jun 26 '15 at 19:55
  • possible duplicate of [Web Scraping data using python?](http://stackoverflow.com/questions/9562963/web-scraping-data-using-python) – Saeid Jun 26 '15 at 19:57
  • possible duplicate of [Web scraping with Python](http://stackoverflow.com/questions/2081586/web-scraping-with-python) –  Jun 26 '15 at 19:58

1 Answers1

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)
lemonhead
  • 5,328
  • 1
  • 13
  • 25