-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsinglefile.py
More file actions
68 lines (50 loc) · 1.68 KB
/
Copy pathsinglefile.py
File metadata and controls
68 lines (50 loc) · 1.68 KB
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
#!/usr/bin/env python3
# coding: utf-8
from urllib.request import urlopen
from urllib.request import Request
import sys
from sqlwriter import *
from general import *
from getMediaDetails import *
from domain import *
from spider import Spider
def inspect_url(page_url,path):
html_string = ''
returnlinks = set()
try:
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
headers = {'Connection' : 'keep-alive', 'User-Agent': user_agent,}
request=Request(page_url,None,headers) #The assembled request
response = urlopen(request)
handle_sql_insert(path,response, page_url, '')
response.close()
except URLError:
print('error encountered, most likely a 404\n')
def inspect_filepath(path, writepath):
if '.' not in path:
print('no file format specified')
sys.exit(1)
handle_sql_insert_filepath(writepath, path)
print('sql script printed at ' + writepath)
#MAIN START
if len(sys.argv) < 2:
print('usage: singleFile <url/filepath>')
sys.exit(0)
filepath = sys.argv[1]
create_project_dir('scripts')
if filepath.startswith('http://') or filepath.startswith('https://'):
HOMEPAGE = sys.argv[1]
DOMAIN_NAME = get_domain_name(HOMEPAGE)
PROJECT_NAME = (DOMAIN_NAME.split('.'))[0]
FILE_DIRECTORY = 'scripts'
Spider(PROJECT_NAME, HOMEPAGE, DOMAIN_NAME, FILE_DIRECTORY)
else:
writepath = 'scripts/'
filename = filepath.split('/')[-1]
names = filename.split('.')
for i in range(0,len(names)-1):
writepath += names[i] + '.'
writepath += 'sql'
write_file(writepath,'')
print(filename)
inspect_filepath(filepath,writepath)