Attachment 'lfcookie-1.py'

Download

   1 #!/usr/bin/env python
   2 # -*- coding: GB2312 -*-
   3 # xyb at linuxforum.net
   4 
   5 import sys
   6 import ClientCookie
   7 from urllib import urlencode
   8 
   9 # add loader
  10 cookies = ClientCookie.LWPCookieJar()
  11 opener = ClientCookie.build_opener(
  12         ClientCookie.HTTPCookieProcessor(cookies),
  13         ClientCookie.HTTPRefererProcessor,
  14         ClientCookie.HTTPEquivProcessor,
  15         ClientCookie.HTTPRefreshProcessor,
  16         ClientCookie.SeekableProcessor)
  17 opener.addheaders = [
  18         ("User-agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031107 Debian/1.5-3"),
  19         ("Accept", "text/html, image/jpeg, image/png, text/*, image/*, */*")]
  20 ClientCookie.install_opener(opener)
  21 
  22 # check args
  23 if len(sys.argv) <= 2:
  24     print "Usage: %s USERNAME PASSWORD" % (sys.argv[0])
  25     sys.exit(1)
  26 else:
  27     UserName = sys.argv[1]
  28     Password = sys.argv[2]
  29 
  30 # login
  31 data = {
  32         'Loginname': UserName,
  33         'Loginpass': Password,
  34         'firstlogin': 1,
  35         'option': 'µÇÈëÂÛ̳'
  36         }
  37 urldata = urlencode(data)
  38 r = ClientCookie.urlopen("http://www.linuxforum.net/forum/start_page.php", urldata)
  39 
  40 # show result
  41 results = r.read()
  42 open('start.html', 'w').write(results)
  43 
  44 # then, user page
  45 r = ClientCookie.urlopen("http://www.linuxforum.net/forum/login.php?Cat=")
  46 results = r.read()
  47 open('user.html', 'w').write(results)
  48 
  49 # read messages
  50 r = ClientCookie.urlopen("http://www.linuxforum.net/forum/viewmessages.php?Cat=&box=received")
  51 results = r.read()
  52 open('inbox.html', 'w').write(results)
  53 
  54 # save cookies to file
  55 cookies.save("./cookies")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-05-11 08:52:18, 1.5 KB) [[attachment:lfcookie-1.py]]
  • [get | view] (2021-05-11 08:52:18, 1.3 KB) [[attachment:lfcookie-2.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.