Skip to content

Instantly share code, notes, and snippets.

@maksimKorzh
Created January 28, 2020 16:57
Show Gist options
  • Save maksimKorzh/c9bbdbd33efaf57fece523f8014c7cb5 to your computer and use it in GitHub Desktop.
Save maksimKorzh/c9bbdbd33efaf57fece523f8014c7cb5 to your computer and use it in GitHub Desktop.
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