python 一个小脚本,用于提取喜欢GSCPC Facebook页面的人的姓名

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 一个小脚本,用于提取喜欢GSCPC Facebook页面的人的姓名相关的知识,希望对你有一定的参考价值。

# 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

以上是关于python 一个小脚本,用于提取喜欢GSCPC Facebook页面的人的姓名的主要内容,如果未能解决你的问题,请参考以下文章

python Python脚本,用于Scrapes Sitemap并将URL,标题和标签提取到Elasticsearch

从 python 脚本中提取参数

9个实用的Python小技巧,让你编写出更快更好的脚本!

python 用于从文本文件中提取电子邮件地址的python脚本。您可以将其传递给多个文件。它将电子邮件地址打印到stdout,on

来自雅虎的python lxml etree小程序信息

python 用于在python中创建新目录并向其写入文件的小脚本。