-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cuenca-mx/scrapper-dhl
Scrapper dhl
- Loading branch information
Showing
23 changed files
with
7,631 additions
and
207 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__all__ = ['__version__', 'Client'] | ||
|
||
|
||
from .client import Client | ||
from .version import __version__ |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class DhlmexException(Exception): | ||
""" | ||
An error has occurred during DHL scrapping | ||
""" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
__all__ = ['Resource'] | ||
__all__ = ['Guide', 'PostCode', 'Resource'] | ||
|
||
from .base import Resource | ||
from .guides import Guide | ||
from .post_codes import PostCode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,57 @@ | ||
from typing import ClassVar | ||
import re | ||
from typing import ClassVar, Dict | ||
|
||
from bs4 import BeautifulSoup | ||
from requests import Response | ||
|
||
from dhlmex.exceptions import DhlmexException | ||
|
||
|
||
class Resource: | ||
_client: ClassVar['cepmex.Client'] # type: ignore | ||
_client: ClassVar["dhlmex.Client"] # type: ignore | ||
_urls: Dict[str, str] = { | ||
'login': '/jsp/app/login/login.xhtml', | ||
'home': '/jsp/app/inicio/inicio.xhtml', | ||
'guide': '/jsp/app/cliente/impresionClienteSubUsuario.xhtml', | ||
'capture': '/jsp/app/cliente/capturaDatosImpresionClienteSU.xhtml', | ||
'print': '/jsp/app/cliente/guiasImpresas.xhtml', | ||
'pdf': '/generaImpresionPDF', | ||
} | ||
_actions: Dict[str, Dict[str, str]] = { | ||
'close': { | ||
'text': 'Cerrar Sesión', | ||
'code': 'j_id9:j_id26', | ||
'end': 'j_id9:j_id30', | ||
}, | ||
'print': { | ||
'text': 'Impresión Sub Usuario', | ||
'code': 'j_id9:j_id14', | ||
'end': 'j_id9:j_id16', | ||
}, | ||
'download': { | ||
'text': 'Guías Impresas', | ||
'code': 'j_id9:j_id18', | ||
'end': 'j_id9:j_id10', | ||
}, | ||
} | ||
|
||
@staticmethod | ||
def get_data(resp: Response, action: Dict) -> Dict: | ||
if 'Login / Admin' in resp.text: | ||
raise DhlmexException('Client not logged in') | ||
soup = BeautifulSoup(resp.text, features='html.parser') | ||
view_state = soup.find('input', id='javax.faces.ViewState').attrs[ | ||
'value' | ||
] | ||
js = soup.find('a', text=action['text']).attrs['onclick'] | ||
matches = re.findall(r"\'(.+?)\'", js) | ||
form_ids = [match for match in matches if match.startswith('j_id')] | ||
j_pair_id = form_ids[1].split(',')[0] | ||
j_id = form_ids[0] | ||
|
||
return { | ||
j_id: j_id, | ||
j_pair_id: action['code'], | ||
'javax.faces.ViewState': view_state, | ||
action['end']: action['end'], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Destination: | ||
company: str | ||
contact: str | ||
mail: str | ||
phone: str | ||
address1: str | ||
postal_code: str | ||
neighborhood: str | ||
city: str | ||
state: str |
Oops, something went wrong.