Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 518837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:58:42+00:00 2026-05-13T07:58:42+00:00

I thought I would write some quick code to download the number of fans

  • 0

I thought I would write some quick code to download the number of “fans” a Facebook page has.

For some reason, despite a fair number of iterations I’ve tried, I can’t get the following code to pick out the number of fans in the HTML. None of the other solutions I found on the web correctly match the regex in this case either. Surely it is possible to have some wildcard between the two matching bits?

The text I’d like to match against is “6 of X fans“, where X is an arbitrary number of fans a page has – I would like to get this number.

I was thinking of polling this data intermittently and writing to a file but I haven’t gotten around to that yet. I’m also wondering if this is headed in the right direction, as the code seems pretty clunky. 🙂

import urllib
import re

fbhandle = urllib.urlopen('http://www.facebook.com/Microsoft')
pattern = "6 of(.*)fans" #this wild card doesnt appear to work?
compiled = re.compile(pattern)

for lines in fbhandle.readlines():
        ms = compiled.match(lines)
        print ms #debugging
        if ms: break
#ms.group()
print ms
fbhandle.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:58:42+00:00Added an answer on May 13, 2026 at 7:58 am
    import urllib
    import re
    
    fbhandle = urllib.urlopen('http://www.facebook.com/Microsoft')
    pattern = "6 of(.*)fans" #this wild card doesnt appear to work?
    compiled = re.compile(pattern)
    
    ms = compiled.search(fbhandle.read())
    print ms.group(1).strip()
    fbhandle.close()
    

    You needed to use re.search() instead. Using re.match() tries to match the pattern against the whole document, but really you’re just trying to match a piece inside the document. The code above prints: 79,110. Of course, this will probably be a different number by the time it gets run by someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write some code that would loop though all rows of a
I'm trying to write some reasonably generic networking code. I have several kinds of
I thought I would try and write a program that would paint a ball,
Since I have started learning OpenGL, I thought I would as well write a
Occasionally, I will write some code with way more parentheses than I like. if(!(new
I'm having some trouble with what I thought would be a simple problem. I'd
I face a recurring problem in the code I write: modifying some global value
This is what I thought would be a simple select clause, however the following
I am looking to do something I thought would be fairly straight forward, Adding
I'm being stymied by what I thought would be the relatively simple task of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.