Created
October 12, 2015 19:49
-
-
Save maptastik/a004850e09c0beb02de0 to your computer and use it in GitHub Desktop.
A little script to extract the names of people who like the GSCPC Facebook page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first, you'll need to login to facebook and go to the fans page | |
# https://www.facebook.com/browse/page_fans/?page_id=868110399935068 | |
# navigate down the page until there are no more like to load | |
# open developer tools and copy the page html | |
# paste it into an html file and save | |
# in the command prompt, navigate to the directorty with your facebook html file | |
# start a local server `python -m SimpleHTTPServer` | |
# this uses lxml and requests | |
# pip install lxml | |
from lxml import html | |
# pip install requests | |
import requests | |
import datetime | |
import csv | |
env = "C:\\Users\\ryan cooper\\Desktop\\temp\\" | |
# Set a variable that gets the html file where you saved the like page's source | |
# You may have to change the URL depending on what you named the file | |
page = requests.get('http://localhost:8000/fbook.html') | |
tree = html.fromstring(page.text) | |
# Names of likers are within an <a> tag wrapped by <div class="fsl fwl fcb"> | |
like = tree.xpath('//div[@class="fsl fwb fcb"]//a/text()') | |
print like | |
now = datetime.datetime.now() | |
csvfile = env + "facbook-likes-" + str(now.year) + str(now.month) + str(now.day) + ".csv" | |
with open(csvfile, "w") as output: | |
writer = csv.writer(output, lineterminator='\n') | |
for val in like: | |
writer.writerow([val]) | |
# Mostly drawn from: | |
# http://docs.python-guide.org/en/latest/scenarios/scrape/ | |
# http://gis.stackexchange.com/a/72476 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment