Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
university_analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robin Stecher
university_analysis
Commits
a3ca3f1e
Commit
a3ca3f1e
authored
Apr 1, 2024
by
Robin Stecher
Browse files
Options
Downloads
Patches
Plain Diff
Improved documentation for url_grabber.py
parent
f78d1a07
No related branches found
No related tags found
1 merge request
!1
Dev
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/url_grabber.py
+10
-5
10 additions, 5 deletions
src/url_grabber.py
with
10 additions
and
5 deletions
src/url_grabber.py
+
10
−
5
View file @
a3ca3f1e
...
...
@@ -3,12 +3,17 @@ from bs4 import BeautifulSoup
def
get_urls_from_website
(
url
:
str
)
->
[
str
]:
"""
Method fetches all href urls on the specified url by scraping the website from url
:param url: The url where the urls should be loaded from
:return: Returns a [str] array of href urls on the given website url
"""
headers
=
{
'
User-Agent
'
:
'
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
'
}
page
=
requests
.
get
(
url
,
allow_redirects
=
True
,
headers
=
headers
)
soup
=
BeautifulSoup
(
page
.
text
,
features
=
"
html.parser
"
)
all_link_elements
=
soup
.
find_all
(
"
a
"
,
href
=
True
)
page
=
requests
.
get
(
url
,
allow_redirects
=
True
,
headers
=
headers
)
# get website
soup
=
BeautifulSoup
(
page
.
text
,
features
=
"
html.parser
"
)
# parse to bs4
all_link_elements
=
soup
.
find_all
(
"
a
"
,
href
=
True
)
# get all <a> tag elements
hrefs
=
[]
for
a
in
all_link_elements
:
hrefs
.
append
(
a
[
'
href
'
])
for
a
in
all_link_elements
:
# Loop through <a> elements
hrefs
.
append
(
a
[
'
href
'
])
# Collect url
return
hrefs
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment