Skip to content

Commit

Permalink
Add http exception handling logic for vet restaurant
Browse files Browse the repository at this point in the history
  • Loading branch information
GoGiants1 committed Jul 29, 2024
1 parent 3f166fa commit e892bc8
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions crawlers/base_crawler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from abc import ABCMeta, abstractmethod
import re
import datetime
from bs4 import BeautifulSoup
from pytz import timezone
import urllib3
import json
import re
from abc import ABCMeta, abstractmethod

import aiohttp
import urllib3
from bs4 import BeautifulSoup
from pytz import timezone


def text_normalizer(text, only_letters=False):
Expand Down Expand Up @@ -189,15 +190,20 @@ async def run(self, url=None, **kwargs):
urllib3.disable_warnings()
if url is None:
url = self.url
async with aiohttp.ClientSession(headers=self.headers, connector=aiohttp.TCPConnector(ssl=False)) as session:
async with session.get(url) as response:
try:
try:
async with aiohttp.ClientSession(
headers=self.headers, connector=aiohttp.TCPConnector(ssl=False)
) as session:
async with session.get(url) as response:
if response.status != 200:
print(f"Failed to fetch {url}: Status code {response.status}")
return
html = await response.read()
# html = await response.text()
soup = BeautifulSoup(html, "html.parser")
self.crawl(soup, **kwargs)
except Exception as e:
print(f"Error in Run: {str(e)}")
except Exception as e:
print(f"Error in Run: {str(e)}")

def normalize(self, meal, **kwargs):
for normalizer_cls in self.normalizer_classes:
Expand Down

0 comments on commit e892bc8

Please sign in to comment.