Created
August 1, 2014 13:59
-
-
Save bigeagle/40e6a3dd94051970af6b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python2 | |
# -*- coding:utf-8 -*- | |
import requests | |
import time | |
from pyquery import PyQuery as pq | |
from urlparse import urlparse, parse_qs | |
backup_file = "backup.txt" | |
base_url = "http://3g.renren.com/" | |
status_list_url = base_url + "/status/getdoing.do?sid={}" | |
headers = { | |
"Host": "3g.renren.com", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0", | |
"Referer": base_url, | |
} | |
login_info = { | |
"email": "", | |
"password": "", | |
} | |
loginPage = requests.get(base_url).content | |
dom = pq(loginPage) | |
login_action_url = dom(".sec > form").attr("action") | |
login_data = {pq(x).attr("name"): pq(x).attr("value") for x in dom(".sec > form input")} | |
for k, v in login_info.iteritems(): | |
login_data[k] = v | |
r = requests.post(login_action_url, headers=headers, data=login_data) | |
cookies = r.history[0].cookies | |
queries = parse_qs(urlparse(r.url).query) | |
sid = queries['sid'][0] | |
last_page = False | |
while not last_page: | |
r = requests.get(status_list_url.format(sid)) | |
# r = requests.get(s_url, headers=headers) | |
dom = pq(r.content) | |
if not dom(".list > div.l"): | |
last_page = True | |
else: | |
print dom(".list > div.l > span.gray").text() | |
for i, status_dom in enumerate(dom(".list > div:not(.l)").items()): | |
_links = status_dom.children("a") | |
status_del_url = _links.eq(len(_links)-1).attr("href") | |
t = status_dom.children(".time").remove().text() | |
status_dom.children("a").remove() | |
status_dom.children("em").remove() | |
print status_del_url | |
with open(backup_file, "a") as f: | |
f.write(t.encode("utf_8")) | |
f.write(",\t") | |
f.write(status_dom.text().encode("utf-8")) | |
f.write("\n") | |
r = requests.get(status_del_url) | |
dom = pq(r.content) | |
del_action_url = dom(".sform > form").attr("action") | |
post_data = {pq(x).attr("name"): pq(x).attr("value") for x in dom(".sform > form input[type='hidden']")} | |
requests.post(del_action_url, post_data) | |
time.sleep(10) | |
print "删完了" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment