-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
### PyCharm ### | ||
.idea/ | ||
.idea* | ||
__pycache__/ | ||
*.pyc | ||
|
||
### Visual Studio Code ### | ||
.vscode/* | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
from time import sleep | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from utils import control_target, manage_target, is_404 | ||
|
||
pages = [] | ||
TARGET_URL = "http://localhost:5500" | ||
|
||
|
||
def get_links(directory, url): | ||
def get_links(url): | ||
global pages | ||
try: | ||
html = requests.get(f'{url}{directory}').text | ||
soup = BeautifulSoup(html, "html.parser") | ||
for link in soup.find_all("a"): | ||
if "href" in link.attrs: | ||
if link.attrs["href"] not in pages: | ||
new_page = link.attrs["href"] | ||
pages.append(new_page) | ||
get_links(new_page, url) | ||
except: | ||
sleep(1) | ||
|
||
html = requests.get(f'{url}').text | ||
|
||
soup = BeautifulSoup(html, "html.parser") | ||
for link in soup.find_all("a"): | ||
if "href" in link.attrs: | ||
potential_page = manage_target(TARGET_URL, link.attrs["href"]) | ||
if (potential_page not in pages) and (control_target(TARGET_URL, potential_page)) and (not is_404(potential_page)): | ||
print(url, " ~~> ", potential_page) | ||
pages.append(potential_page) | ||
get_links(potential_page) | ||
|
||
|
||
def main(): | ||
get_links("", "http://localhost:5500/") | ||
print("\n".join(pages)) | ||
get_links(TARGET_URL) | ||
#print("\n".join(pages)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
print('bye!!') |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import requests | ||
|
||
|
||
def control_target(TARGET_URL, test_url): | ||
return True if test_url.startswith(TARGET_URL) else False | ||
|
||
def manage_target(TARGET_URL, target): | ||
if target.startswith("/"): | ||
target = TARGET_URL + target | ||
return target | ||
|
||
def is_404(url): | ||
r = requests.get(f'{url}') | ||
return True if r.status_code == 404 else False | ||
|
||
def robotsChecker(): | ||
pass |