Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Anomaly Detection in Microservices Systems
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sashika sewwandi
Anomaly Detection in Microservices Systems
Commits
9d254642
Commit
9d254642
authored
May 14, 2022
by
sashika sewwandi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
d63690ad
Pipeline
#5787
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
test_class.py
test_class.py
+55
-0
No files found.
test_class.py
0 → 100644
View file @
9d254642
from
__future__
import
print_function
import
csv
import
requests
from
bs4
import
BeautifulSoup
class
ScrapData
:
def
__init__
(
self
):
self
.
page_link
=
None
self
.
quotes
=
[]
self
.
zip_file_path
=
None
self
.
download_url
=
None
def
create_download_url
(
self
):
try
:
self
.
page_link
=
"http://www.values.com/inspirational-quotes"
page_response
=
requests
.
get
(
self
.
page_link
,
timeout
=
5
)
page_string
=
page_response
.
content
# Download latest release
soup
=
BeautifulSoup
(
page_string
,
"html.parser"
)
r
=
soup
.
find
(
'div'
,
attrs
=
{
'id'
:
'all_quotes'
})
for
row
in
r
.
findAll
(
'div'
,
attrs
=
{
'class'
:
'col-6 col-lg-4 text-center margin-30px-bottom '
'sm-margin-30px-top'
}):
quote
=
{
'theme'
:
row
.
h5
.
text
,
'url'
:
row
.
a
[
'href'
],
'img'
:
row
.
img
[
'src'
],
'lines'
:
row
.
img
[
'alt'
]
.
split
(
" #"
)[
0
],
'author'
:
row
.
img
[
'alt'
]
.
split
(
" #"
)[
1
]}
self
.
quotes
.
append
(
quote
)
except
Exception
as
e
:
print
(
"Can't scrape data from this site:"
,
self
.
page_link
)
print
(
e
)
def
download_zip_file
(
self
):
try
:
filename
=
'quotes.csv'
with
open
(
filename
,
'w'
,
newline
=
''
)
as
f
:
w
=
csv
.
DictWriter
(
f
,
[
'theme'
,
'url'
,
'img'
,
'lines'
,
'author'
])
w
.
writeheader
()
for
quote
in
self
.
quotes
:
w
.
writerow
(
quote
)
except
Exception
as
e
:
print
(
"file download is unsuccessful"
)
print
(
e
)
def
invoke
(
self
):
self
.
create_download_url
()
self
.
download_zip_file
()
if
__name__
==
'__main__'
:
custom_driver_params
=
'Create a new file WebScraping inspirational-quotes data'
new_file
=
ScrapData
()
new_file
.
invoke
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment