Wraps Pip packages (beautifulsoup and requests) to a more concise content extractor
Project description
Gencon Miner
A general content miner that leverages on Beautiful Soup and Requests to handle extraction. The main goal is to always imagine in terms of targetting parent elements in an HTML form then getting group of tags given that parent.
from gencon_miner import GenconMiner
From URL
url_miner = GenconMiner(url="http://google.com")
txt = url_miner.extract('title')
print(txt[0].text) # Google
From text
text_miner = GenconMiner(text="<p class='myclass'>Hello</p>")
txt = text_miner.extract('.myclass')
print(txt[0].text) # Hello
Convert all tag content to string
Note that contents in a tag will be delimited using newline.
meaning_of_life = """
<p class='myclass'>
Hello
<span>darkness my old friend</span>
</p>
<b>And another one</b>
"""
bulk_miner = GenconMiner(text=meaning_of_life)
print(bulk_miner.to_text()) # Hello\ndarkness my old friend\nAnd another one
Parent to target
Use-case on walking document and extracting the targets.
song_of_the_day = """
<table id="mother">
<tr>
<td class="target-1">Mamma Mia</td>
<td class="target-2">Here I go again</td>
<td class="target-3">My my</td>
<td class="target-4">How can I resist you</td>
</tr>
</table>
"""
walk_miner = GenconMiner(text=song_of_the_day)
print(walk_miner.extract('#mother', '.target-1')[0].text) # Mamma Mia
print(walk_miner.extract('#mother', '.target-3')[0].text) # My my
print(walk_miner.extract('#mother', 'td'))
# [
# <td class="target-1">Mamma Mia</td>,
# <td class="target-2">Here I go again</td>,
# <td class="target-3">My my</td>,
# <td class="target-4">How can I resist you</td>
# ]
Author
Almer Mendoza
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
GenconMiner-0.1.7.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file GenconMiner-0.1.7.tar.gz
.
File metadata
- Download URL: GenconMiner-0.1.7.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.16 CPython/3.7.3 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1576f32f6af443ca444c3cc8ed2c94a1072908ac98bb944d873b07c997cb220 |
|
MD5 | f63019474cb78f75f95ad66837b0bed5 |
|
BLAKE2b-256 | 9529474d36ebe4e47fa9fd4bd125b72090ae431bd54e2a114a5634d821df39b3 |
File details
Details for the file GenconMiner-0.1.7-py2.py3-none-any.whl
.
File metadata
- Download URL: GenconMiner-0.1.7-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.16 CPython/3.7.3 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c0f6677acb51ae9906415437a47ff7c689815263531c79c1c86c102d5b47c0a |
|
MD5 | f31c26bd3b12f40d05c9145846b71ccf |
|
BLAKE2b-256 | 6e64aab7dd924a06d4c5f3f6d7da7884afcdce0df60e672bfc08d3f720f9e7b0 |