Create html_scraper.py
Browse files- helper/html_scraper.py +19 -0
helper/html_scraper.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
+
from .asyncioPoliciesFix import decorator_asyncio_fix
|
4 |
+
from constants.headers import HEADER_AIO
|
5 |
+
|
6 |
+
HTTP_PROXY = os.environ.get("HTTP_PROXY", None)
|
7 |
+
|
8 |
+
|
9 |
+
class Scraper:
|
10 |
+
@decorator_asyncio_fix
|
11 |
+
async def _get_html(self, session, url):
|
12 |
+
try:
|
13 |
+
async with session.get(url, headers=HEADER_AIO, proxy=HTTP_PROXY) as r:
|
14 |
+
return await r.text()
|
15 |
+
except:
|
16 |
+
return None
|
17 |
+
|
18 |
+
async def get_all_results(self, session, url):
|
19 |
+
return await asyncio.gather(asyncio.create_task(self._get_html(session, url)))
|