-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
phpBBLogin.py
87 lines (63 loc) · 2.94 KB
/
phpBBLogin.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# *-* coding: utf-8 *-*
# Copyright (C) 2014 by Ángel Guzmán Maeso, shakaran at gmail dot com
# phpBBLogin is a simple python script for login in phpBB forums and extract links
# from forum threads (for example with direct download files)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# pip install html5lib beautifulsoup4 requests
import requests
from bs4 import BeautifulSoup
class phpBBLogin:
FORUM_URL = 'http://somesite.com/forum/ucp.php?mode=login'
DOWNLOAD_URL = 'http://somesite.com/forum/viewtopic.php?f=155&t=1117041'
login_params = {
'username': 'your_username',
'password': 'your_password',
'autologin': 'on',
'redirect' : 'index.php',
'login' : 'Login',
}
def __init__(self):
self.session = requests.session()
self.fetch_sid()
self.login_post()
def fetch_sid(self):
r = self.session.get(self.FORUM_URL, verify=False)
if r:
if r.status_code == requests.codes.ok:
form_page = BeautifulSoup(str(r.content))
form_element = form_page.find('form', { 'id':'login'})
self.sid = form_element['action'].split('sid=')[1]
self.login_params['sid'] = self.sid
def fetch_links(self):
downloaded_data = self.session.get(self.DOWNLOAD_URL)
thread_data = BeautifulSoup(str(downloaded_data.content))
thread_content = thread_data.find('div', { 'class':'content'})
if thread_content:
links = thread_content.find_all('a', {'class' : 'postlink'})
if links:
for link in links:
print(str(link['href']))
def login_post(self):
r = self.session.post(self.FORUM_URL, data=self.login_params, verify=False)
if r:
if r.status_code == requests.codes.ok:
#print (r.cookies)
#print (r.content)
self.fetch_links()
else:
print('Error: ' + str(r.status_code))
else:
print('Error: could not create the request')
if __name__ == "__main__":
phpBBLogin()