模擬登入刪除貼文


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import mechanize
from colorama import init
from colorama import Fore, Back, Style

init()

def main():
# Login
print(Fore.CYAN + "Try to login plurk account")
browser = mechanize.Browser()
browser.open("http://www.plurk.com/m/login")
browser.select_form(nr=0)
browser['username'] = "====Your Username Here===="
browser['password'] = "====Your Password Here===="
response = browser.submit()
print("")

while(1):
# Go to my plurks tab
browser.open("http://www.plurk.com/m/?mode=my")
print(Fore.MAGENTA + "Try to enter your pluk list")

# Get plurks count
remain = sum(1 for _ in browser.links(url_regex=r"^/m/p/[0-9A-Za-z]+$"))
print(Fore.YELLOW + "In your remain plurk: {0}".format(remain))
if remain <= 0:
break

# Goto post detail page
browser.follow_link(url_regex=r"^/m/p/[0-9A-Za-z]+$", nr=0)
print(Fore.GREEN + "In post detail page : {0}".format(browser.geturl()))

# Goto delete page
browser.follow_link(url_regex=r'^/m/p/[0-9A-Za-z]+/d$')
print(Fore.GREEN + "In post delete page : {0}".format(browser.geturl()))

# Remove the plurk
browser.select_form(nr=0)
browser.submit()
print(Fore.GREEN + "In post removed page: {0}".format(browser.geturl()))
print("")

if __name__ == "__main__":
main()