Created
January 28, 2020 16:57
-
-
Save maksimKorzh/c9bbdbd33efaf57fece523f8014c7cb5 to your computer and use it in GitHub Desktop.
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
import requests | |
from bs4 import BeautifulSoup | |
import csv | |
import json | |
class Onetimescraper: | |
results = [] | |
def fetch(self, url): | |
print('HTTP GET request to URL: %s' % url, end='') | |
res = requests.get(url) | |
print(' | Status code: %s' % res.status_code) | |
return res | |
def to_html(self, html): | |
with open('res.html', 'w') as html_file: | |
html_file.write(html) | |
def from_html(self): | |
html = '' | |
with open('res.html', 'r') as html_file: | |
for line in html_file.read(): | |
html += line | |
return html | |
def to_csv(self): | |
with open('results.csv', 'w') as csv_file: | |
writer = csv.DictWriter(csv_file, fieldnames=self.results[0].keys()) | |
writer.writeheader() | |
for row in self.results: | |
writer.writerow(row) | |
print('"results.csv" has been written successfully!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment