PK!Hcs""gencon_miner/GenconMiner.pyimport requests from bs4 import BeautifulSoup from .exceptions import NoInputForProcessing, InputOverloadForProcessing, UrlContentNotAccessible class GenconMiner: def __init__(self, url: str=None, text: str=None) -> None: if url is None and text is None: raise NoInputForProcessing('Should either have url= or text=') if url and text: raise InputOverloadForProcessing('Having both set is anti-pattern; consider using either but not both') self.url = url self.text = text def _get_html_data(self) -> None: html_data = requests.get(self.url) print(html_data) if not html_data or html_data.status_code > 400: raise UrlContentNotAccessible('Cannot access url: {}'.format(self.url)) self.text = html_data.text def _extract_from_url(self, parent: str, target: str=None) -> list: self._get_html_data() return self._extract_from_text(parent, target) def _extract_from_text(self, parent: str, target: str=None) -> list: bs_txt = BeautifulSoup(self.text, 'html.parser') if target is not None: parent_txt = bs_txt.select_one(parent) return parent_txt.select(target) parent_txt = bs_txt.select(parent) return parent_txt def extract(self, parent: str, target: str=None) -> list: if self.url: return self._extract_from_url(parent, target) if self.text: return self._extract_from_text(parent, target) raise NoInputForProcessing('Should either have url= or text= on initialization') def to_text(self) -> str: if self.url and not self.text: self._get_html_data() soup = BeautifulSoup(self.text, 'html.parser') [s.extract() for s in soup(['script', 'style'])] return soup.get_text("\n", strip=True) def to_soup(self) -> str: if self.url and not self.text: self._get_html_data() soup = BeautifulSoup(self.text, 'html.parser') return soup PK!n<<gencon_miner/__init__.pyfrom .GenconMiner import GenconMiner __version__ = '0.1.0' PK!\Tgencon_miner/exceptions.pyclass Error(Exception): def __init__(self, mssg): super().__init__(mssg) def __str__(self): return repr(self.mssg) class NoInputForProcessing(Error): def __init__(self, mssg): super().__init__(mssg) class InputOverloadForProcessing(Error): def __init__(self, mssg): super().__init__(mssg) class UrlContentNotAccessible(Error): def __init__(self, mssg): super().__init__(mssg) PK!H"+,genconminer-0.1.1.dist-info/entry_points.txtN+I/N.,()*-,I- XA\\PK!O&&#genconminer-0.1.1.dist-info/LICENSECopyright (c) 2012-2018 Almer Mendoza Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTU!genconminer-0.1.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H}x= $genconminer-0.1.1.dist-info/METADATAV]o6|X([W6ޡ5Hr!FUJ?M pgv);H'J'9X*؈qxmҬ"ҵ*LRwƲrj^eVW%"!Wl$)׆ ce G;m'DΕ6S,u>(+lV$T̅EN\TnMD4"s^lWjU8_eW֓Y?:ŇLZ抑{} E~{Iei'kS#sT5+YI[7G^.=Ω;sh+'љGؿ8v/7Wp566t0CcݪAyL√0ją+mU;B: [ޝ+ݶi.qGnjW5LfKr¦c99iRv PJS;cX }^\Yx>uRWoB<<u¶Rnm,gϲ.K:^_*%$<?E;h~5sF PK!H״Ĕ"genconminer-0.1.1.dist-info/RECORD}ɒ@{ ؀r [+ͅM*J~f:b%\ P}:#g!IXH_%~X6WEn&hG}֎#ǐr3W3M4M_V𾬫;ZpJ69LDF!/o`D^%`oHn]JGy}˻<=`DqASBY*Y"ڍ DɌtȊ>2G! PHj>ro/|װ5ɚXKp6c%B7ҺC$u$EB(2<' oҲIǧl@>ys2גkݨ0\e fj{mYDU)N:,f  mpV^I2JoeD[a>PK!Hcs""gencon_miner/GenconMiner.pyPK!n<<[gencon_miner/__init__.pyPK!\Tgencon_miner/exceptions.pyPK!H"+, genconminer-0.1.1.dist-info/entry_points.txtPK!O&&#) genconminer-0.1.1.dist-info/LICENSEPK!HڽTU!genconminer-0.1.1.dist-info/WHEELPK!H}x= $#genconminer-0.1.1.dist-info/METADATAPK!H״Ĕ"bgenconminer-0.1.1.dist-info/RECORDPKs6