Last active
July 17, 2020 15:51
-
-
Save ebraminio/e66885524c4021df1e41b3b354ab3d8c to your computer and use it in GitHub Desktop.
files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
import bs4 | |
import requests | |
def extract_files(site_name): | |
dirs = deque('/') | |
result = [] | |
while len(dirs): | |
path = dirs.pop() | |
page = bs4.BeautifulSoup(requests.get(site_name + path).text, 'html.parser') | |
for link in page.find_all('a'): | |
href = link['href'] | |
assert not href.startswith('/') | |
if href.startswith('..'): continue | |
if href.endswith('/'): dirs.append(path + href) | |
else: result.append(path + href) | |
print(path) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment