-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_crawler.py
More file actions
27 lines (22 loc) · 784 Bytes
/
Copy pathbasic_crawler.py
File metadata and controls
27 lines (22 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
from bs4 import BeautifulSoup, SoupStrainer
from infoCrawler.requestAssistant import RequestHeaderGenerator
class BasicCrawler:
"""
docstring for BasicCrawler.
"""
def __init__(self):
self.rhg = RequestHeaderGenerator()
def get_soup(self, url):
try:
response = requests.get(url, headers = self.rhg.getRandomRequestHeader())
except Exception as err:
print(f"Error: {err}")
return False
if response.status_code == 200:
soup = BeautifulSoup(response.content, "lxml")
print(f"OK! Url: {url}")
return soup
else:
print(f'Something went wrong. Got the following response code: {response.status_code}')
return None