Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DB
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caballero
DB
Commits
09518761
Commit
09518761
authored
8 years ago
by
djcaballero
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web-scraper.py
+44
-0
44 additions, 0 deletions
web-scraper.py
with
44 additions
and
0 deletions
web-scraper.py
0 → 100644
+
44
−
0
View file @
09518761
#import libraries
import
unicodecsv
as
csv
import
requests
from
bs4
import
BeautifulSoup
def
getSoup
(
url
):
#query the website
page_query
=
requests
.
get
(
url
)
#parse the html using BS
soup_page
=
BeautifulSoup
(
page_query
.
text
,
'
html.parser
'
)
return
soup_page
def
main
():
#open csv.file and create csv.writer
csv_file
=
open
(
'
heise_articles.csv
'
,
'
wb
'
)
writer
=
csv
.
writer
(
csv_file
,
delimiter
=
'
,
'
)
#store the urls to be used in urls
urls
=
[]
url1
=
'
https://www.heise.de/thema/https
'
url2
=
'
https://www.heise.de/thema/https?seite=1
'
url3
=
'
https://www.heise.de/thema/https?seite=2
'
url4
=
'
https://www.heise.de/thema/https?seite=3
'
urls
.
append
(
url1
)
urls
.
append
(
url2
)
urls
.
append
(
url3
)
urls
.
append
(
url4
)
#get the parent <div class="keywordliste">...<\div>
for
i
in
urls
:
parent_div
=
getSoup
(
i
).
find
(
'
div
'
,
attrs
=
{
'
class
'
:
'
keywordliste
'
})
#get the <nav>...<\nav>
nav_tag
=
parent_div
.
nav
#get all headers
articles
=
nav_tag
.
findAll
(
'
header
'
)
#print all headers
for
article
in
articles
:
article
=
article
.
text
.
encode
(
'
utf-8
'
)
writer
.
writerow
([
article
])
if
__name__
==
'
__main__
'
:
main
()
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