How capture the members amount from a facebook group page?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

How capture the members amount from a facebook group page?

Post by shamigc » Thu Sep 22, 2016 4:21 am

Hi,

I need to update the members number from a collection of 300 facebook groups pages. I have no problem displaying every group page, and I have tried to use text recognition commands without success, Could you please help to get that number?

Thank you,
Salvador
Thanks,
Salvador Hernandez

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How capture the members amount from a facebook group pag

Post by Marcus Tettmar » Thu Sep 22, 2016 9:52 am

To get data from a web page I would not use text recognition. Use the IE functions to extract the data directly from the HTML element.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Thu Sep 22, 2016 1:42 pm

Thanks for your answer, Could you give me one example of code of how to get the menber number from web page https://www.facebook.com/groups/CompraVentaMonterrey?
Thanks,
Salvador Hernandez

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How capture the members amount from a facebook group pag

Post by Marcus Tettmar » Thu Sep 22, 2016 2:21 pm

If we inspect the element (right click on it and select "Inspect Element") in IE we see this:
count_text.PNG
So we want to extract the SPAN tag with id=count_text:

Code: Select all

IEGetTagsByAttrib>facebook.com/groups/CompraVentaMonterrey,SPAN,id=count_text,T,allCounts
You need to make sure that IE is already open at the page for the above to work. For now, do that manually, but you could have the macro open it and log in if you need to first.

Now, this returns the result in allCounts_1. Of course it will contain:

"133,426 members"

If you just want the numeric value you could parse it out, something like:

Code: Select all

StringReplace>allCounts_1,{","},,the_text
RegEx>\d*,the_text,0,matches,nm,0
MessageModal>matches_1
Have a look at this article for more help in identifying elements:
http://help.mjtnet.com/article/13-findi ... -web-sites
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Thu Sep 22, 2016 3:23 pm

Thank you very much for your example. Is there a way to use meta characters, something like:

IEGetTagsByAttrib>facebook.com/groups/*,SPAN,id=count_text,T,allCounts

Thank you
Thanks,
Salvador Hernandez

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How capture the members amount from a facebook group pag

Post by Marcus Tettmar » Thu Sep 22, 2016 3:48 pm

It's already a substring match. So you just need:

IEGetTagsByAttrib>facebook.com/groups/,SPAN,id=count_text,T,allCounts

That would get it from the first IE instance it finds with "facebook.com/groups/" anywhere in the URL.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Thu Sep 22, 2016 11:01 pm

Thank you, I found a problem when a page is blocked, for example: https://www.facebook.com/groups/buenaventamt. I tried to fix it with the following code:

Code: Select all

  IEGetTagsByAttrib>facebook.com/groups/,H2,Class=uiHeaderTitle,T,blockedPage
  If>blockedPage_Number<>0
    IEGetTagsByAttrib>facebook.com/groups/,SPAN,id=count_text,T,allCounts
    StringReplace>allCounts_1,{","},,the_text
    RegEx>\d*,the_text,0,matches,nm,0
    Let>MembersNumber=matches_1
  Else
    Let>MembersNumber=0
  EndIf
But I get error "No matching IE instance found" when a page is not blocked, Could you please help me?

Thank you
Thanks,
Salvador Hernandez

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How capture the members amount from a facebook group pag

Post by Marcus Tettmar » Fri Sep 23, 2016 9:37 am

That tag doesn't exist when not blocked. You could extract the html from the containing element to check for existence, or, easier, just ignore any errors around this bit of code. Since you only want to do it when it's blocked anyway, that would be fine. Something like this:

Code: Select all

Let>MembersNumber=0
Let>IGNOREERRORS=1
IEGetTagsByAttrib>facebook.com/groups/,H2,Class=uiHeaderTitle,T,blockedPage
  If>blockedPage_Number<>0
    IEGetTagsByAttrib>facebook.com/groups/,SPAN,id=count_text,T,allCounts
    StringReplace>allCounts_1,{","},,the_text
    RegEx>\d*,the_text,0,matches,nm,0
    Let>MembersNumber=matches_1
EndIf
Let>IGNOREERRORS=0
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Tue Sep 27, 2016 9:35 am

I want to improve the code assigning zero to the variable who saves the number of members, so the next time start with zero members, and if there is an error, it will return zero member, and I can detect easily an error. Is it correct the following code for that idea:

Code: Select all

Let>IGNOREERRORS=1
IEGetTagsByAttrib>facebook.com/groups/,H2,Class=uiHeaderTitle,T,blockedPage
  If>blockedPage_Number<>0
    IEGetTagsByAttrib>facebook.com/groups/,SPAN,id=count_text,T,allCounts
    StringReplace>allCounts_1,{","},,the_text
    RegEx>\d*,the_text,0,matches,nm,0
    Let>MembersNumber=matches_1
    'Clear matches_1, so next time if there is an error, MembersNumber will be zero, and I will detect it easily
    Let>matches_1=0
EndIf
Let>IGNOREERRORS=0
Thanks,
Salvador Hernandez

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Fri Sep 30, 2016 10:10 am

Marcus, what did you think about my previous post?
Thanks,
Salvador Hernandez

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How capture the members amount from a facebook group pag

Post by Marcus Tettmar » Fri Sep 30, 2016 11:26 am

You could do that. But I would simply set MembersNumber to zero before the check:

Code: Select all

Let>MembersNumber=0
Let>IGNOREERRORS=1
IEGetTagsByAttrib>facebook.com/groups/,H2,Class=uiHeaderTitle,T,blockedPage
  If>blockedPage_Number<>0
    IEGetTagsByAttrib>facebook.com/groups/,SPAN,id=count_text,T,allCounts
    StringReplace>allCounts_1,{","},,the_text
    RegEx>\d*,the_text,0,matches,nm,0
    Let>MembersNumber=matches_1
EndIf
Let>IGNOREERRORS=0
//If MembersNumber is zero here then we either got an error, or there are no members!

But also you can check to see if you got an error by checking LASTERROR. Please see Error Handling in help file.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

shamigc
Junior Coder
Posts: 37
Joined: Wed Oct 22, 2003 11:38 am
Location: Monterrey, Mexico

Re: How capture the members amount from a facebook group pag

Post by shamigc » Thu Jan 05, 2017 5:18 am

Marcus,

Hi, I need your help, please, The macro to get the members number of every groups link was working for months, but sudenly failed. I created a video, you can watch it on the following link https://youtu.be/Dvadgtw6Qhc. Cold you please help me to fix it?
FacebookMembers.scp
Thanks,
Salvador
Thanks,
Salvador Hernandez

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How capture the members amount from a facebook group pag

Post by Dorian (MJT support) » Mon Jan 23, 2017 8:04 pm

It's quite probable the code on the page has changed. This could cause it to fail. Have you tried running through the same steps you already performed to create this originally? I'd be very surprised if that didn't fix it.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts