Advertisement
LOoLzeC

unpage.py

Apr 14th, 2019
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. # Copyright: Deray
  2.  
  3.  
  4. import requests,bs4,re,mechanize,json
  5.  
  6. print("\t[ Coded By Deray ]\n")
  7. class unpage:
  8.     def __init__(self):
  9.         self.br=mechanize.Browser()
  10.         self.br.set_handle_redirect(True)
  11.         self.br.set_handle_robots(False)
  12.         self.s=requests.Session()
  13.         self.config=json.loads(json.dumps(
  14.             {"email":raw_input("?: email: "),
  15.             "pass":raw_input("?: passs: ")}))
  16.            
  17.         self.url="https://www.facebook.com/{}"
  18.         self.lv()
  19.        
  20.     def lv(self):
  21.         print("+ login ...")
  22.         self.br.open(
  23.             "https://mbasic.facebook.com/login")
  24.         self.br._factory.is_html=True
  25.         self.br.select_form(nr=0)
  26.         self.br.form["email"]="%s"%(self.config["email"])
  27.         self.br.form["pass"]="%s"%(self.config["pass"])
  28.         z=self.br.submit().geturl()
  29.         if not "save-device" in z or "m_sess" in z:
  30.             exit("!: login failed.")
  31.         s=self.s.post(
  32.         "https://mbasic.facebook.com/login",
  33.             data={
  34.                 "email":self.config["email"],
  35.                 "pass":self.config["pass"]}
  36.         ).url
  37.         if "save-device" in s or "m_sess" in s:
  38.             self.d(self.url.format(
  39.                 "browse/other_connections_of"))
  40.         else:exit("!: failed login.")
  41.        
  42.     def d(self,url):
  43.         pepek=[]
  44.         bz=bs4.BeautifulSoup(self.s.get(url).text,
  45.             features="html.parser")
  46.         for x in bz.find_all("a",href=True):
  47.             if "fref=pb" in x["href"]:
  48.                 if "&" in x["href"]:
  49.                     continue
  50.                 else:
  51.                     pepek.append(x["href"])
  52.         if len(pepek) ==0:
  53.             print("!: no one page you likes.")
  54.         else:
  55.             print("* unliking %s page ..."%(len(pepek)))
  56.             print
  57.             map(self.m,pepek)
  58.        
  59.     def m(self,url):
  60.         try:
  61.             self.br.open(
  62.             url.replace("www",
  63.                 "mbasic").encode("ascii","ignore"))
  64.             self.br._factory.is_html=True
  65.             a=bs4.BeautifulSoup(
  66.                 self.br.response().read(),
  67.             features="html.parser")
  68.             d=a.find("title").renderContents()
  69.             for x in a.find_all("a",href=True):
  70.                 if "unfan" in x["href"]:
  71.                     self.br.open(
  72.                         self.br.click_link(text="%s"%(x.text)))
  73.             print("^ %s -> unliked."%(d))
  74.         except:
  75.             print "!: cant decode ascii characters:",url
  76.             pass
  77.                
  78. unpage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement