erging with main
Browse files- LICENSE.md +15 -0
- Pipfile +18 -0
- Pipfile.lock +287 -0
- README.md +30 -3
- data/2025-03-25_tramites_gobbo.raw.csv +0 -0
- main.py +37 -0
- src/common/__init__.py +0 -0
- src/common/csv.py +48 -0
- src/common/custom_logger.py +94 -0
- src/common/selectors.py +47 -0
- src/common/time.py +26 -0
- src/locators.py +134 -0
- src/scraper.py +278 -0
LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gobbo-datos Extractor de datos plataforma gob.bo
|
| 2 |
+
Copyright (C) 2025 Rodrigo Garcia <rgarcia@laotra.red>
|
| 3 |
+
|
| 4 |
+
This program is free software: you can redistribute it and/or modify
|
| 5 |
+
it under the terms of the GNU General Public License as published by
|
| 6 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 7 |
+
(at your option) any later version.
|
| 8 |
+
|
| 9 |
+
This program is distributed in the hope that it will be useful,
|
| 10 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
GNU General Public License for more details.
|
| 13 |
+
|
| 14 |
+
You should have received a copy of the GNU General Public License
|
| 15 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
Pipfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[[source]]
|
| 2 |
+
url = "https://pypi.org/simple"
|
| 3 |
+
verify_ssl = true
|
| 4 |
+
name = "pypi"
|
| 5 |
+
|
| 6 |
+
[packages]
|
| 7 |
+
sqlalchemy = "*"
|
| 8 |
+
asyncio = "*"
|
| 9 |
+
beautifulsoup4 = "*"
|
| 10 |
+
playsound = "*"
|
| 11 |
+
playwright = "*"
|
| 12 |
+
asyncclick = "*"
|
| 13 |
+
psycopg2 = "*"
|
| 14 |
+
|
| 15 |
+
[dev-packages]
|
| 16 |
+
|
| 17 |
+
[requires]
|
| 18 |
+
python_version = "3.10"
|
Pipfile.lock
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_meta": {
|
| 3 |
+
"hash": {
|
| 4 |
+
"sha256": "6c2de6fe6991e4d4c43b902aefb83678695db24bdbc30dfacdf93ceb25f1c6ec"
|
| 5 |
+
},
|
| 6 |
+
"pipfile-spec": 6,
|
| 7 |
+
"requires": {
|
| 8 |
+
"python_version": "3.10"
|
| 9 |
+
},
|
| 10 |
+
"sources": [
|
| 11 |
+
{
|
| 12 |
+
"name": "pypi",
|
| 13 |
+
"url": "https://pypi.org/simple",
|
| 14 |
+
"verify_ssl": true
|
| 15 |
+
}
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"default": {
|
| 19 |
+
"anyio": {
|
| 20 |
+
"hashes": [
|
| 21 |
+
"sha256:673c0c244e15788651a4ff38710fea9675823028a6f08a5eda409e0c9840a028",
|
| 22 |
+
"sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c"
|
| 23 |
+
],
|
| 24 |
+
"markers": "python_version >= '3.9'",
|
| 25 |
+
"version": "==4.9.0"
|
| 26 |
+
},
|
| 27 |
+
"asyncclick": {
|
| 28 |
+
"hashes": [
|
| 29 |
+
"sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c",
|
| 30 |
+
"sha256:be146a2d8075d4fe372ff4e877f23c8b5af269d16705c1948123b9415f6fd678",
|
| 31 |
+
"sha256:eb1ccb44bc767f8f0695d592c7806fdf5bd575605b4ee246ffd5fadbcfdbd7c6"
|
| 32 |
+
],
|
| 33 |
+
"index": "pypi",
|
| 34 |
+
"markers": "python_version >= '3.9'",
|
| 35 |
+
"version": "==8.1.8.0"
|
| 36 |
+
},
|
| 37 |
+
"asyncio": {
|
| 38 |
+
"hashes": [
|
| 39 |
+
"sha256:83360ff8bc97980e4ff25c964c7bd3923d333d177aa4f7fb736b019f26c7cb41",
|
| 40 |
+
"sha256:b62c9157d36187eca799c378e572c969f0da87cd5fc42ca372d92cdb06e7e1de",
|
| 41 |
+
"sha256:c46a87b48213d7464f22d9a497b9eef8c1928b68320a2fa94240f969f6fec08c",
|
| 42 |
+
"sha256:c4d18b22701821de07bd6aea8b53d21449ec0ec5680645e5317062ea21817d2d"
|
| 43 |
+
],
|
| 44 |
+
"index": "pypi",
|
| 45 |
+
"version": "==3.4.3"
|
| 46 |
+
},
|
| 47 |
+
"beautifulsoup4": {
|
| 48 |
+
"hashes": [
|
| 49 |
+
"sha256:1bd32405dacc920b42b83ba01644747ed77456a65760e285fbc47633ceddaf8b",
|
| 50 |
+
"sha256:99045d7d3f08f91f0d656bc9b7efbae189426cd913d830294a15eefa0ea4df16"
|
| 51 |
+
],
|
| 52 |
+
"index": "pypi",
|
| 53 |
+
"markers": "python_full_version >= '3.7.0'",
|
| 54 |
+
"version": "==4.13.3"
|
| 55 |
+
},
|
| 56 |
+
"exceptiongroup": {
|
| 57 |
+
"hashes": [
|
| 58 |
+
"sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b",
|
| 59 |
+
"sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"
|
| 60 |
+
],
|
| 61 |
+
"markers": "python_version < '3.11'",
|
| 62 |
+
"version": "==1.2.2"
|
| 63 |
+
},
|
| 64 |
+
"greenlet": {
|
| 65 |
+
"hashes": [
|
| 66 |
+
"sha256:0153404a4bb921f0ff1abeb5ce8a5131da56b953eda6e14b88dc6bbc04d2049e",
|
| 67 |
+
"sha256:03a088b9de532cbfe2ba2034b2b85e82df37874681e8c470d6fb2f8c04d7e4b7",
|
| 68 |
+
"sha256:04b013dc07c96f83134b1e99888e7a79979f1a247e2a9f59697fa14b5862ed01",
|
| 69 |
+
"sha256:05175c27cb459dcfc05d026c4232f9de8913ed006d42713cb8a5137bd49375f1",
|
| 70 |
+
"sha256:09fc016b73c94e98e29af67ab7b9a879c307c6731a2c9da0db5a7d9b7edd1159",
|
| 71 |
+
"sha256:0bbae94a29c9e5c7e4a2b7f0aae5c17e8e90acbfd3bf6270eeba60c39fce3563",
|
| 72 |
+
"sha256:0fde093fb93f35ca72a556cf72c92ea3ebfda3d79fc35bb19fbe685853869a83",
|
| 73 |
+
"sha256:1443279c19fca463fc33e65ef2a935a5b09bb90f978beab37729e1c3c6c25fe9",
|
| 74 |
+
"sha256:1776fd7f989fc6b8d8c8cb8da1f6b82c5814957264d1f6cf818d475ec2bf6395",
|
| 75 |
+
"sha256:1d3755bcb2e02de341c55b4fca7a745a24a9e7212ac953f6b3a48d117d7257aa",
|
| 76 |
+
"sha256:23f20bb60ae298d7d8656c6ec6db134bca379ecefadb0b19ce6f19d1f232a942",
|
| 77 |
+
"sha256:275f72decf9932639c1c6dd1013a1bc266438eb32710016a1c742df5da6e60a1",
|
| 78 |
+
"sha256:2846930c65b47d70b9d178e89c7e1a69c95c1f68ea5aa0a58646b7a96df12441",
|
| 79 |
+
"sha256:3319aa75e0e0639bc15ff54ca327e8dc7a6fe404003496e3c6925cd3142e0e22",
|
| 80 |
+
"sha256:346bed03fe47414091be4ad44786d1bd8bef0c3fcad6ed3dee074a032ab408a9",
|
| 81 |
+
"sha256:36b89d13c49216cadb828db8dfa6ce86bbbc476a82d3a6c397f0efae0525bdd0",
|
| 82 |
+
"sha256:37b9de5a96111fc15418819ab4c4432e4f3c2ede61e660b1e33971eba26ef9ba",
|
| 83 |
+
"sha256:396979749bd95f018296af156201d6211240e7a23090f50a8d5d18c370084dc3",
|
| 84 |
+
"sha256:3b2813dc3de8c1ee3f924e4d4227999285fd335d1bcc0d2be6dc3f1f6a318ec1",
|
| 85 |
+
"sha256:411f015496fec93c1c8cd4e5238da364e1da7a124bcb293f085bf2860c32c6f6",
|
| 86 |
+
"sha256:47da355d8687fd65240c364c90a31569a133b7b60de111c255ef5b606f2ae291",
|
| 87 |
+
"sha256:48ca08c771c268a768087b408658e216133aecd835c0ded47ce955381105ba39",
|
| 88 |
+
"sha256:4afe7ea89de619adc868e087b4d2359282058479d7cfb94970adf4b55284574d",
|
| 89 |
+
"sha256:4ce3ac6cdb6adf7946475d7ef31777c26d94bccc377e070a7986bd2d5c515467",
|
| 90 |
+
"sha256:4ead44c85f8ab905852d3de8d86f6f8baf77109f9da589cb4fa142bd3b57b475",
|
| 91 |
+
"sha256:54558ea205654b50c438029505def3834e80f0869a70fb15b871c29b4575ddef",
|
| 92 |
+
"sha256:5e06afd14cbaf9e00899fae69b24a32f2196c19de08fcb9f4779dd4f004e5e7c",
|
| 93 |
+
"sha256:62ee94988d6b4722ce0028644418d93a52429e977d742ca2ccbe1c4f4a792511",
|
| 94 |
+
"sha256:63e4844797b975b9af3a3fb8f7866ff08775f5426925e1e0bbcfe7932059a12c",
|
| 95 |
+
"sha256:6510bf84a6b643dabba74d3049ead221257603a253d0a9873f55f6a59a65f822",
|
| 96 |
+
"sha256:667a9706c970cb552ede35aee17339a18e8f2a87a51fba2ed39ceeeb1004798a",
|
| 97 |
+
"sha256:6ef9ea3f137e5711f0dbe5f9263e8c009b7069d8a1acea822bd5e9dae0ae49c8",
|
| 98 |
+
"sha256:7017b2be767b9d43cc31416aba48aab0d2309ee31b4dbf10a1d38fb7972bdf9d",
|
| 99 |
+
"sha256:7124e16b4c55d417577c2077be379514321916d5790fa287c9ed6f23bd2ffd01",
|
| 100 |
+
"sha256:73aaad12ac0ff500f62cebed98d8789198ea0e6f233421059fa68a5aa7220145",
|
| 101 |
+
"sha256:77c386de38a60d1dfb8e55b8c1101d68c79dfdd25c7095d51fec2dd800892b80",
|
| 102 |
+
"sha256:7876452af029456b3f3549b696bb36a06db7c90747740c5302f74a9e9fa14b13",
|
| 103 |
+
"sha256:7939aa3ca7d2a1593596e7ac6d59391ff30281ef280d8632fa03d81f7c5f955e",
|
| 104 |
+
"sha256:8320f64b777d00dd7ccdade271eaf0cad6636343293a25074cc5566160e4de7b",
|
| 105 |
+
"sha256:85f3ff71e2e60bd4b4932a043fbbe0f499e263c628390b285cb599154a3b03b1",
|
| 106 |
+
"sha256:8b8b36671f10ba80e159378df9c4f15c14098c4fd73a36b9ad715f057272fbef",
|
| 107 |
+
"sha256:93147c513fac16385d1036b7e5b102c7fbbdb163d556b791f0f11eada7ba65dc",
|
| 108 |
+
"sha256:935e943ec47c4afab8965954bf49bfa639c05d4ccf9ef6e924188f762145c0ff",
|
| 109 |
+
"sha256:94b6150a85e1b33b40b1464a3f9988dcc5251d6ed06842abff82e42632fac120",
|
| 110 |
+
"sha256:94ebba31df2aa506d7b14866fed00ac141a867e63143fe5bca82a8e503b36437",
|
| 111 |
+
"sha256:95ffcf719966dd7c453f908e208e14cde192e09fde6c7186c8f1896ef778d8cd",
|
| 112 |
+
"sha256:98884ecf2ffb7d7fe6bd517e8eb99d31ff7855a840fa6d0d63cd07c037f6a981",
|
| 113 |
+
"sha256:99cfaa2110534e2cf3ba31a7abcac9d328d1d9f1b95beede58294a60348fba36",
|
| 114 |
+
"sha256:9e8f8c9cb53cdac7ba9793c276acd90168f416b9ce36799b9b885790f8ad6c0a",
|
| 115 |
+
"sha256:a0dfc6c143b519113354e780a50381508139b07d2177cb6ad6a08278ec655798",
|
| 116 |
+
"sha256:b2795058c23988728eec1f36a4e5e4ebad22f8320c85f3587b539b9ac84128d7",
|
| 117 |
+
"sha256:b42703b1cf69f2aa1df7d1030b9d77d3e584a70755674d60e710f0af570f3761",
|
| 118 |
+
"sha256:b7cede291382a78f7bb5f04a529cb18e068dd29e0fb27376074b6d0317bf4dd0",
|
| 119 |
+
"sha256:b8a678974d1f3aa55f6cc34dc480169d58f2e6d8958895d68845fa4ab566509e",
|
| 120 |
+
"sha256:b8da394b34370874b4572676f36acabac172602abf054cbc4ac910219f3340af",
|
| 121 |
+
"sha256:c3a701fe5a9695b238503ce5bbe8218e03c3bcccf7e204e455e7462d770268aa",
|
| 122 |
+
"sha256:c4aab7f6381f38a4b42f269057aee279ab0fc7bf2e929e3d4abfae97b682a12c",
|
| 123 |
+
"sha256:ca9d0ff5ad43e785350894d97e13633a66e2b50000e8a183a50a88d834752d42",
|
| 124 |
+
"sha256:d0028e725ee18175c6e422797c407874da24381ce0690d6b9396c204c7f7276e",
|
| 125 |
+
"sha256:d21e10da6ec19b457b82636209cbe2331ff4306b54d06fa04b7c138ba18c8a81",
|
| 126 |
+
"sha256:d5e975ca70269d66d17dd995dafc06f1b06e8cb1ec1e9ed54c1d1e4a7c4cf26e",
|
| 127 |
+
"sha256:da7a9bff22ce038e19bf62c4dd1ec8391062878710ded0a845bcf47cc0200617",
|
| 128 |
+
"sha256:db32b5348615a04b82240cc67983cb315309e88d444a288934ee6ceaebcad6cc",
|
| 129 |
+
"sha256:dcc62f31eae24de7f8dce72134c8651c58000d3b1868e01392baea7c32c247de",
|
| 130 |
+
"sha256:dfc59d69fc48664bc693842bd57acfdd490acafda1ab52c7836e3fc75c90a111",
|
| 131 |
+
"sha256:e347b3bfcf985a05e8c0b7d462ba6f15b1ee1c909e2dcad795e49e91b152c383",
|
| 132 |
+
"sha256:e4d333e558953648ca09d64f13e6d8f0523fa705f51cae3f03b5983489958c70",
|
| 133 |
+
"sha256:ed10eac5830befbdd0c32f83e8aa6288361597550ba669b04c48f0f9a2c843c6",
|
| 134 |
+
"sha256:efc0f674aa41b92da8c49e0346318c6075d734994c3c4e4430b1c3f853e498e4",
|
| 135 |
+
"sha256:f1695e76146579f8c06c1509c7ce4dfe0706f49c6831a817ac04eebb2fd02011",
|
| 136 |
+
"sha256:f1d4aeb8891338e60d1ab6127af1fe45def5259def8094b9c7e34690c8858803",
|
| 137 |
+
"sha256:f406b22b7c9a9b4f8aa9d2ab13d6ae0ac3e85c9a809bd590ad53fed2bf70dc79",
|
| 138 |
+
"sha256:f6ff3b14f2df4c41660a7dec01045a045653998784bf8cfcb5a525bdffffbc8f"
|
| 139 |
+
],
|
| 140 |
+
"markers": "python_version >= '3.7'",
|
| 141 |
+
"version": "==3.1.1"
|
| 142 |
+
},
|
| 143 |
+
"idna": {
|
| 144 |
+
"hashes": [
|
| 145 |
+
"sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9",
|
| 146 |
+
"sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"
|
| 147 |
+
],
|
| 148 |
+
"markers": "python_version >= '3.6'",
|
| 149 |
+
"version": "==3.10"
|
| 150 |
+
},
|
| 151 |
+
"playsound": {
|
| 152 |
+
"hashes": [
|
| 153 |
+
"sha256:cc6ed11d773034b0ef624e6bb4bf50f4b76b8414a59ce6d38afb89b423297ced"
|
| 154 |
+
],
|
| 155 |
+
"index": "pypi",
|
| 156 |
+
"version": "==1.3.0"
|
| 157 |
+
},
|
| 158 |
+
"playwright": {
|
| 159 |
+
"hashes": [
|
| 160 |
+
"sha256:2e0ae6eb44297b24738e1a6d9c580ca4243b4e21b7e65cf936a71492c08dd0d4",
|
| 161 |
+
"sha256:4cef804991867ea27f608b70fa288ee52a57651e22d02ab287f98f8620b9408c",
|
| 162 |
+
"sha256:814e4ec2a1a0d6f6221f075622c06b31ceb2bdc6d622258cfefed900c01569ae",
|
| 163 |
+
"sha256:9ece9316c5d383aed1a207f079fc2d552fff92184f0ecf37cc596e912d00a8c3",
|
| 164 |
+
"sha256:ab4c0ff00bded52c946be60734868febc964c8a08a9b448d7c20cb3811c6521c",
|
| 165 |
+
"sha256:bcaaa3d5d73bda659bfb9ff2a288b51e85a91bd89eda86eaf8186550973e416a",
|
| 166 |
+
"sha256:d5c9f67bc6ef49094618991c78a1466c5bac5ed09157660d78b8510b77f92746"
|
| 167 |
+
],
|
| 168 |
+
"index": "pypi",
|
| 169 |
+
"markers": "python_version >= '3.9'",
|
| 170 |
+
"version": "==1.51.0"
|
| 171 |
+
},
|
| 172 |
+
"psycopg2": {
|
| 173 |
+
"hashes": [
|
| 174 |
+
"sha256:0435034157049f6846e95103bd8f5a668788dd913a7c30162ca9503fdf542cb4",
|
| 175 |
+
"sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11",
|
| 176 |
+
"sha256:47c4f9875125344f4c2b870e41b6aad585901318068acd01de93f3677a6522c2",
|
| 177 |
+
"sha256:4a579d6243da40a7b3182e0430493dbd55950c493d8c68f4eec0b302f6bbf20e",
|
| 178 |
+
"sha256:5df2b672140f95adb453af93a7d669d7a7bf0a56bcd26f1502329166f4a61716",
|
| 179 |
+
"sha256:65a63d7ab0e067e2cdb3cf266de39663203d38d6a8ed97f5ca0cb315c73fe067",
|
| 180 |
+
"sha256:88138c8dedcbfa96408023ea2b0c369eda40fe5d75002c0964c78f46f11fa442",
|
| 181 |
+
"sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2",
|
| 182 |
+
"sha256:9d5b3b94b79a844a986d029eee38998232451119ad653aea42bb9220a8c5066b",
|
| 183 |
+
"sha256:c6f7b8561225f9e711a9c47087388a97fdc948211c10a4bccbf0ba68ab7b3b5a"
|
| 184 |
+
],
|
| 185 |
+
"index": "pypi",
|
| 186 |
+
"markers": "python_version >= '3.8'",
|
| 187 |
+
"version": "==2.9.10"
|
| 188 |
+
},
|
| 189 |
+
"pyee": {
|
| 190 |
+
"hashes": [
|
| 191 |
+
"sha256:18a19c650556bb6b32b406d7f017c8f513aceed1ef7ca618fb65de7bd2d347ef",
|
| 192 |
+
"sha256:bbc33c09e2ff827f74191e3e5bbc6be7da02f627b7ec30d86f5ce1a6fb2424a3"
|
| 193 |
+
],
|
| 194 |
+
"markers": "python_version >= '3.8'",
|
| 195 |
+
"version": "==12.1.1"
|
| 196 |
+
},
|
| 197 |
+
"sniffio": {
|
| 198 |
+
"hashes": [
|
| 199 |
+
"sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2",
|
| 200 |
+
"sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
|
| 201 |
+
],
|
| 202 |
+
"markers": "python_version >= '3.7'",
|
| 203 |
+
"version": "==1.3.1"
|
| 204 |
+
},
|
| 205 |
+
"soupsieve": {
|
| 206 |
+
"hashes": [
|
| 207 |
+
"sha256:e2e68417777af359ec65daac1057404a3c8a5455bb8abc36f1a9866ab1a51abb",
|
| 208 |
+
"sha256:e72c4ff06e4fb6e4b5a9f0f55fe6e81514581fca1515028625d0f299c602ccc9"
|
| 209 |
+
],
|
| 210 |
+
"markers": "python_version >= '3.8'",
|
| 211 |
+
"version": "==2.6"
|
| 212 |
+
},
|
| 213 |
+
"sqlalchemy": {
|
| 214 |
+
"hashes": [
|
| 215 |
+
"sha256:018ee97c558b499b58935c5a152aeabf6d36b3d55d91656abeb6d93d663c0c4c",
|
| 216 |
+
"sha256:01da15490c9df352fbc29859d3c7ba9cd1377791faeeb47c100832004c99472c",
|
| 217 |
+
"sha256:04545042969833cb92e13b0a3019549d284fd2423f318b6ba10e7aa687690a3c",
|
| 218 |
+
"sha256:06205eb98cb3dd52133ca6818bf5542397f1dd1b69f7ea28aa84413897380b06",
|
| 219 |
+
"sha256:08cf721bbd4391a0e765fe0fe8816e81d9f43cece54fdb5ac465c56efafecb3d",
|
| 220 |
+
"sha256:0d7e3866eb52d914aea50c9be74184a0feb86f9af8aaaa4daefe52b69378db0b",
|
| 221 |
+
"sha256:125a7763b263218a80759ad9ae2f3610aaf2c2fbbd78fff088d584edf81f3782",
|
| 222 |
+
"sha256:23c5aa33c01bd898f879db158537d7e7568b503b15aad60ea0c8da8109adf3e7",
|
| 223 |
+
"sha256:2600a50d590c22d99c424c394236899ba72f849a02b10e65b4c70149606408b5",
|
| 224 |
+
"sha256:2d7332868ce891eda48896131991f7f2be572d65b41a4050957242f8e935d5d7",
|
| 225 |
+
"sha256:2ed107331d188a286611cea9022de0afc437dd2d3c168e368169f27aa0f61338",
|
| 226 |
+
"sha256:3395e7ed89c6d264d38bea3bfb22ffe868f906a7985d03546ec7dc30221ea980",
|
| 227 |
+
"sha256:344cd1ec2b3c6bdd5dfde7ba7e3b879e0f8dd44181f16b895940be9b842fd2b6",
|
| 228 |
+
"sha256:34d5c49f18778a3665d707e6286545a30339ad545950773d43977e504815fa70",
|
| 229 |
+
"sha256:35e72518615aa5384ef4fae828e3af1b43102458b74a8c481f69af8abf7e802a",
|
| 230 |
+
"sha256:3eb14ba1a9d07c88669b7faf8f589be67871d6409305e73e036321d89f1d904e",
|
| 231 |
+
"sha256:412c6c126369ddae171c13987b38df5122cb92015cba6f9ee1193b867f3f1530",
|
| 232 |
+
"sha256:4600c7a659d381146e1160235918826c50c80994e07c5b26946a3e7ec6c99249",
|
| 233 |
+
"sha256:463ecfb907b256e94bfe7bcb31a6d8c7bc96eca7cbe39803e448a58bb9fcad02",
|
| 234 |
+
"sha256:4a06e6c8e31c98ddc770734c63903e39f1947c9e3e5e4bef515c5491b7737dde",
|
| 235 |
+
"sha256:4b2de1523d46e7016afc7e42db239bd41f2163316935de7c84d0e19af7e69538",
|
| 236 |
+
"sha256:4dabd775fd66cf17f31f8625fc0e4cfc5765f7982f94dc09b9e5868182cb71c0",
|
| 237 |
+
"sha256:4eff9c270afd23e2746e921e80182872058a7a592017b2713f33f96cc5f82e32",
|
| 238 |
+
"sha256:52607d0ebea43cf214e2ee84a6a76bc774176f97c5a774ce33277514875a718e",
|
| 239 |
+
"sha256:533e0f66c32093a987a30df3ad6ed21170db9d581d0b38e71396c49718fbb1ca",
|
| 240 |
+
"sha256:5493a8120d6fc185f60e7254fc056a6742f1db68c0f849cfc9ab46163c21df47",
|
| 241 |
+
"sha256:5d2d1fe548def3267b4c70a8568f108d1fed7cbbeccb9cc166e05af2abc25c22",
|
| 242 |
+
"sha256:5dfbc543578058c340360f851ddcecd7a1e26b0d9b5b69259b526da9edfa8875",
|
| 243 |
+
"sha256:66a40003bc244e4ad86b72abb9965d304726d05a939e8c09ce844d27af9e6d37",
|
| 244 |
+
"sha256:67de057fbcb04a066171bd9ee6bcb58738d89378ee3cabff0bffbf343ae1c787",
|
| 245 |
+
"sha256:6827f8c1b2f13f1420545bd6d5b3f9e0b85fe750388425be53d23c760dcf176b",
|
| 246 |
+
"sha256:6b35e07f1d57b79b86a7de8ecdcefb78485dab9851b9638c2c793c50203b2ae8",
|
| 247 |
+
"sha256:7399d45b62d755e9ebba94eb89437f80512c08edde8c63716552a3aade61eb42",
|
| 248 |
+
"sha256:788b6ff6728072b313802be13e88113c33696a9a1f2f6d634a97c20f7ef5ccce",
|
| 249 |
+
"sha256:78f1b79132a69fe8bd6b5d91ef433c8eb40688ba782b26f8c9f3d2d9ca23626f",
|
| 250 |
+
"sha256:79f4f502125a41b1b3b34449e747a6abfd52a709d539ea7769101696bdca6716",
|
| 251 |
+
"sha256:7a8517b6d4005facdbd7eb4e8cf54797dbca100a7df459fdaff4c5123265c1cd",
|
| 252 |
+
"sha256:7bd5c5ee1448b6408734eaa29c0d820d061ae18cb17232ce37848376dcfa3e92",
|
| 253 |
+
"sha256:7f5243357e6da9a90c56282f64b50d29cba2ee1f745381174caacc50d501b109",
|
| 254 |
+
"sha256:805cb481474e111ee3687c9047c5f3286e62496f09c0e82e8853338aaaa348f8",
|
| 255 |
+
"sha256:871f55e478b5a648c08dd24af44345406d0e636ffe021d64c9b57a4a11518304",
|
| 256 |
+
"sha256:87a1ce1f5e5dc4b6f4e0aac34e7bb535cb23bd4f5d9c799ed1633b65c2bcad8c",
|
| 257 |
+
"sha256:8a10ca7f8a1ea0fd5630f02feb055b0f5cdfcd07bb3715fc1b6f8cb72bf114e4",
|
| 258 |
+
"sha256:995c2bacdddcb640c2ca558e6760383dcdd68830160af92b5c6e6928ffd259b4",
|
| 259 |
+
"sha256:9f03143f8f851dd8de6b0c10784363712058f38209e926723c80654c1b40327a",
|
| 260 |
+
"sha256:a1c6b0a5e3e326a466d809b651c63f278b1256146a377a528b6938a279da334f",
|
| 261 |
+
"sha256:a28f9c238f1e143ff42ab3ba27990dfb964e5d413c0eb001b88794c5c4a528a9",
|
| 262 |
+
"sha256:b2cf5b5ddb69142511d5559c427ff00ec8c0919a1e6c09486e9c32636ea2b9dd",
|
| 263 |
+
"sha256:b761a6847f96fdc2d002e29e9e9ac2439c13b919adfd64e8ef49e75f6355c548",
|
| 264 |
+
"sha256:bf555f3e25ac3a70c67807b2949bfe15f377a40df84b71ab2c58d8593a1e036e",
|
| 265 |
+
"sha256:c08a972cbac2a14810463aec3a47ff218bb00c1a607e6689b531a7c589c50723",
|
| 266 |
+
"sha256:c457a38351fb6234781d054260c60e531047e4d07beca1889b558ff73dc2014b",
|
| 267 |
+
"sha256:c4c433f78c2908ae352848f56589c02b982d0e741b7905228fad628999799de4",
|
| 268 |
+
"sha256:d9f119e7736967c0ea03aff91ac7d04555ee038caf89bb855d93bbd04ae85b41",
|
| 269 |
+
"sha256:e6b0a1c7ed54a5361aaebb910c1fa864bae34273662bb4ff788a527eafd6e14d",
|
| 270 |
+
"sha256:f2bcb085faffcacf9319b1b1445a7e1cfdc6fb46c03f2dce7bc2d9a4b3c1cdc5",
|
| 271 |
+
"sha256:fe193d3ae297c423e0e567e240b4324d6b6c280a048e64c77a3ea6886cc2aa87"
|
| 272 |
+
],
|
| 273 |
+
"index": "pypi",
|
| 274 |
+
"markers": "python_version >= '3.7'",
|
| 275 |
+
"version": "==2.0.39"
|
| 276 |
+
},
|
| 277 |
+
"typing-extensions": {
|
| 278 |
+
"hashes": [
|
| 279 |
+
"sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d",
|
| 280 |
+
"sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"
|
| 281 |
+
],
|
| 282 |
+
"markers": "python_version >= '3.8'",
|
| 283 |
+
"version": "==4.12.2"
|
| 284 |
+
}
|
| 285 |
+
},
|
| 286 |
+
"develop": {}
|
| 287 |
+
}
|
README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Extractor de datos plataforma gob.bo
|
| 2 |
+
|
| 3 |
+
Extrae los trámites del portal de trámites gob.bo.
|
| 4 |
+
|
| 5 |
+
## Instalación
|
| 6 |
+
|
| 7 |
+
Se debería poder instalar con pipenv, una vez clonado el repositorio
|
| 8 |
+
|
| 9 |
+
1. `pipenv shell`
|
| 10 |
+
2. `pipenv install`
|
| 11 |
+
3. Puede que playwright pida descargar chromium, seguir las instrucciones que aparezcan en la consola.
|
| 12 |
+
|
| 13 |
+
## Ejecución
|
| 14 |
+
|
| 15 |
+
Una vez activado el entorno virtual: `python main.py`.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
language:
|
| 19 |
+
- es
|
| 20 |
+
pretty_name: "Trámites Portal único de trámites de Bolivia gob.bo obtenidos por scraping."
|
| 21 |
+
tags:
|
| 22 |
+
- public
|
| 23 |
+
- procedures
|
| 24 |
+
- gobierno
|
| 25 |
+
- trámites
|
| 26 |
+
- información pública
|
| 27 |
+
license: "Creative Commons Attribution 4.0"
|
| 28 |
+
task_categories:
|
| 29 |
+
- task1
|
| 30 |
+
---
|
data/2025-03-25_tramites_gobbo.raw.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
main.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of gobbo-datos
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import asyncclick as click
|
| 7 |
+
|
| 8 |
+
from playwright.async_api import async_playwright
|
| 9 |
+
from src.common.custom_logger import CustomLogger
|
| 10 |
+
from src.common.time import today_yyyymmdd
|
| 11 |
+
from src.scraper import GobboScrapper
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
LOGGER = CustomLogger('gob.bo scraper ')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@click.command()
|
| 18 |
+
async def scrape_tramites():
|
| 19 |
+
categories = ['Impuestos', 'Bienes Inmuebles', 'Cultura y Turismo',
|
| 20 |
+
'Económico-Productivo',
|
| 21 |
+
'Educación', 'Gobierno', 'Identificación', 'Justicia',
|
| 22 |
+
'Medio Ambiente', 'Salud', 'Transporte']
|
| 23 |
+
|
| 24 |
+
gobbo_scraper = GobboScrapper()
|
| 25 |
+
|
| 26 |
+
filename = f'{today_yyyymmdd()}_tramites_gobbo.csv'
|
| 27 |
+
|
| 28 |
+
async with async_playwright() as p:
|
| 29 |
+
await gobbo_scraper.init(p)
|
| 30 |
+
|
| 31 |
+
for category in categories:
|
| 32 |
+
await gobbo_scraper.scrape_entire_category(category, filename)
|
| 33 |
+
await gobbo_scraper.goto_home()
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == '__main__':
|
| 37 |
+
scrape_tramites(_anyio_backend='asyncio')
|
src/common/__init__.py
ADDED
|
File without changes
|
src/common/csv.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This file is part of Wayrunku. Copyright Rodrigo Garcia
|
| 3 |
+
|
| 4 |
+
Wayrunku is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
| 5 |
+
|
| 6 |
+
Wayrunku is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
| 7 |
+
|
| 8 |
+
You should have received a copy of the GNU General Public License along with Wayrunku. If not, see <https://www.gnu.org/licenses/>.
|
| 9 |
+
"""
|
| 10 |
+
import csv
|
| 11 |
+
from os.path import exists
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def csv_write_headers(filename="bbc.csv", headers=["title", "content", "date", "categories", "url"],
|
| 15 |
+
replace_file=False):
|
| 16 |
+
replace_flag = "w" if replace_file else "a"
|
| 17 |
+
with open(filename, replace_flag, encoding="UTF-8", newline="") as f:
|
| 18 |
+
writer = csv.writer(f)
|
| 19 |
+
writer.writerow(headers)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def csv_columnnames_exist(
|
| 23 |
+
filename="bbc.csv",
|
| 24 |
+
headers=["title", "content", "date", "categories", "url"]):
|
| 25 |
+
file_exists = exists(filename)
|
| 26 |
+
if not file_exists:
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
with open(filename, "r", encoding="UTF-8", newline="") as f:
|
| 30 |
+
firstline = f.readline().rstrip()
|
| 31 |
+
print(f"firstline of '{filename}': {firstline}")
|
| 32 |
+
return firstline == ",".join(headers)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def append_to_csv(article, keys=["title", "content", "date", "categories", "url"], filename="bbc.csv"):
|
| 36 |
+
'''Agrega el contenido de un artículo como nueva fila del archivo dado, seleccionado
|
| 37 |
+
las propiedades del articulo.
|
| 38 |
+
:article (dictionary) con title, categories, content, date and url
|
| 39 |
+
:
|
| 40 |
+
'''
|
| 41 |
+
with open(filename, 'a', encoding='UTF-8', newline='') as f:
|
| 42 |
+
writer = csv.writer(f, delimiter=',')
|
| 43 |
+
|
| 44 |
+
if "categories" in keys:
|
| 45 |
+
article["categories"] = ",".join(article["categories"])
|
| 46 |
+
|
| 47 |
+
row = [article[k] for k in keys]
|
| 48 |
+
writer.writerow(row)
|
src/common/custom_logger.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of gobbo-datos
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import sys
|
| 10 |
+
import traceback
|
| 11 |
+
|
| 12 |
+
class CustomLogger(logging.Logger):
|
| 13 |
+
"""Class to manage a custom logger
|
| 14 |
+
|
| 15 |
+
Parameters
|
| 16 |
+
----------
|
| 17 |
+
logging : obj
|
| 18 |
+
logging object
|
| 19 |
+
"""
|
| 20 |
+
handlers = []
|
| 21 |
+
|
| 22 |
+
def __init__(self, name, logfile="data_app.log", minloglevel="DEBUG"):
|
| 23 |
+
"""Initialize logger
|
| 24 |
+
|
| 25 |
+
Parameters
|
| 26 |
+
----------
|
| 27 |
+
name : context
|
| 28 |
+
context where logger runs
|
| 29 |
+
"""
|
| 30 |
+
logging.Logger.__init__(self, name)
|
| 31 |
+
self.configure(logfile, minloglevel)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def close(self):
|
| 35 |
+
"""Method to close and flush all the handlers
|
| 36 |
+
"""
|
| 37 |
+
for handler in self.handlers:
|
| 38 |
+
handler.flush()
|
| 39 |
+
handler.close()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def configure(self, logfile, minloglevel):
|
| 43 |
+
"""Method to configure handlers, set level and set formatters.
|
| 44 |
+
|
| 45 |
+
logfile: name of the logfile inside `LOG_PATH' defined path
|
| 46 |
+
minloglevel: Default minmum loglevel, either; DEBUG, WARNING, INFO, ERROR, CRITICAL
|
| 47 |
+
"""
|
| 48 |
+
console_handler = logging.StreamHandler()
|
| 49 |
+
|
| 50 |
+
file_handler = logging.FileHandler(
|
| 51 |
+
#filename=str(log_path.joinpath(logfile).absolute()),
|
| 52 |
+
filename='logs/logs.log',
|
| 53 |
+
mode='a'
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
log_level=logging.DEBUG
|
| 57 |
+
if minloglevel == "INFO":
|
| 58 |
+
log_level = logging.INFO
|
| 59 |
+
elif minloglevel == "DEBUG":
|
| 60 |
+
log_level = logging.DEBUG
|
| 61 |
+
elif minloglevel == "WARNING":
|
| 62 |
+
log_level = logging.WARN
|
| 63 |
+
elif minloglevel == "ERROR":
|
| 64 |
+
log_level = logging.ERROR
|
| 65 |
+
elif minloglevel == "CRITICAL":
|
| 66 |
+
log_level = logging.CRITICAL
|
| 67 |
+
|
| 68 |
+
#console_handler.setLevel(logging.ERROR)
|
| 69 |
+
console_handler.setLevel(logging.DEBUG)
|
| 70 |
+
file_handler.setLevel(logging.DEBUG)
|
| 71 |
+
formatter = logging.Formatter(
|
| 72 |
+
"%(asctime)s (%(name)s) -[%(levelname)s] - %(message)s",
|
| 73 |
+
datefmt="%d-%b-%y %H:%M:%S"
|
| 74 |
+
)
|
| 75 |
+
logging.setLevel = log_level
|
| 76 |
+
console_handler.setFormatter(formatter)
|
| 77 |
+
file_handler.setFormatter(formatter)
|
| 78 |
+
self.handlers = self.handlers + [console_handler, file_handler]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def format_exception(self, e):
|
| 82 |
+
"""Logs traceback of exception.
|
| 83 |
+
Based on: https://stackoverflow.com/questions/6086976/how-to-get-a-complete-exception-stack-trace-in-python
|
| 84 |
+
"""
|
| 85 |
+
exception_list = traceback.format_stack()
|
| 86 |
+
exception_list = exception_list[:-2]
|
| 87 |
+
exception_list.extend(traceback.format_tb(sys.exc_info()[2]))
|
| 88 |
+
exception_list.extend(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]))
|
| 89 |
+
|
| 90 |
+
exception_str = "Traceback (most recent call last):\n"
|
| 91 |
+
exception_str += "".join(exception_list)
|
| 92 |
+
# Removing the last \n
|
| 93 |
+
exception_str = exception_str[:-1]
|
| 94 |
+
return exception_str
|
src/common/selectors.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of gobbo-datos
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
from src.common.custom_logger import CustomLogger
|
| 6 |
+
|
| 7 |
+
LOGGER = CustomLogger('selectors 🧰:')
|
| 8 |
+
|
| 9 |
+
def get_selector_value(selector, *args):
|
| 10 |
+
"""Helps checking the selector value.
|
| 11 |
+
Parameters:
|
| 12 |
+
selector (str or function): If it is a function, uses args* to pass the function arguments and return
|
| 13 |
+
a result. Else returns the selector string
|
| 14 |
+
args (list): if `selector' is a function this args are passed as arguments to that function
|
| 15 |
+
Returns:
|
| 16 |
+
str: Resulting selector
|
| 17 |
+
"""
|
| 18 |
+
svalue = ''
|
| 19 |
+
if isinstance(selector['value'], str) is False:
|
| 20 |
+
svalue = selector['value'](*args)
|
| 21 |
+
else:
|
| 22 |
+
svalue = selector['value']
|
| 23 |
+
return svalue
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def get_locator(selector, *args):
|
| 27 |
+
"""Replaces the selector values and returns a valid string to be used in
|
| 28 |
+
playright page.locator"""
|
| 29 |
+
|
| 30 |
+
svalue = get_selector_value(selector, *args)
|
| 31 |
+
if selector['stype'] == 'xpath':
|
| 32 |
+
svalue = f'xpath={svalue}'
|
| 33 |
+
if selector['stype'] == 'css':
|
| 34 |
+
svalue = f'css={svalue}'
|
| 35 |
+
LOGGER.debug(f' locator: {svalue}')
|
| 36 |
+
return svalue
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
async def is_element_located(page, selector, *args):
|
| 40 |
+
"""Tries to get the element from the given selector on the given page obeject.
|
| 41 |
+
If element is not located or visible returns False
|
| 42 |
+
"""
|
| 43 |
+
element = page.locator(get_locator(selector))
|
| 44 |
+
if await element.count() > 0:
|
| 45 |
+
return True
|
| 46 |
+
return False
|
| 47 |
+
|
src/common/time.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of gobbo-datos
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import asyncio, random
|
| 7 |
+
from datetime import datetime as dt
|
| 8 |
+
|
| 9 |
+
async def random_sleep(min_seconds, max_seconds):
|
| 10 |
+
await asyncio.sleep(random.uniform(min_seconds, max_seconds))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def today_yyyymmdd() -> str:
|
| 14 |
+
"""Returns today date in format YYYY-MM-DD"""
|
| 15 |
+
return dt.strftime(dt.now(), '%Y-%m-%d')
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def age_in_days(_datetime) -> int:
|
| 19 |
+
"""Given a datetime returns its age in days.
|
| 20 |
+
Thus the days from that date to today"""
|
| 21 |
+
return (dt.now() - _datetime).days
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def datetime_from_yyyymmdd(datestr: str):
|
| 25 |
+
"""Returns the datetime object from the string in format yyyy-mm-dd"""
|
| 26 |
+
return dt.strptime(datestr, '%Y-%m-%d')
|
src/locators.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of wayrunku-desinformacion-politica
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
locators = {
|
| 7 |
+
'categorias': {
|
| 8 |
+
'linkPorNombre': {
|
| 9 |
+
'stype': 'xpath',
|
| 10 |
+
# Ejemplos: Bienes Inmuebles, Cultura y Turismo, Impuestos
|
| 11 |
+
'value': lambda nombre: f'//div[@style="text-align: center;"]//div[@class="pb-2 md:pb-5"]/div/span[text()=" {nombre} "]'
|
| 12 |
+
}
|
| 13 |
+
},
|
| 14 |
+
'listaTramites': {
|
| 15 |
+
'linkPorTramite': {
|
| 16 |
+
'stype': 'xpath',
|
| 17 |
+
'value': '//div[@class="pa-5 my-10"]//div[@class="flex-grow"]/div/a/span/..'
|
| 18 |
+
},
|
| 19 |
+
'listPags': {
|
| 20 |
+
'stype': 'css',
|
| 21 |
+
'value': 'div.el-pagination > ul.el-pager li'
|
| 22 |
+
},
|
| 23 |
+
'pagSiguienteBtn': {
|
| 24 |
+
# cuando no hay mas paginas este elemento no existe
|
| 25 |
+
'stype': 'xpath',
|
| 26 |
+
'value': '//button[@class="btn-next"][not(@disabled)]'
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
},
|
| 30 |
+
'tramites': {
|
| 31 |
+
'titulo': {
|
| 32 |
+
'stype': 'xpath',
|
| 33 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]/div/span[contains(@class, "uppercase")]'
|
| 34 |
+
},
|
| 35 |
+
'institucion': {
|
| 36 |
+
'stype': 'xpath',
|
| 37 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]/div/a[@class="text-primary font-semibold"]'
|
| 38 |
+
|
| 39 |
+
},
|
| 40 |
+
'descripcion': {
|
| 41 |
+
'stype': 'xpath',
|
| 42 |
+
'value': '//div[@class="py-5 text-justify animate-paragraph"]'
|
| 43 |
+
},
|
| 44 |
+
'contacto': {
|
| 45 |
+
'stype': 'xpath',
|
| 46 |
+
#'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//div[1]/a'
|
| 47 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//div/a[contains(@href, "mailto:")]'
|
| 48 |
+
},
|
| 49 |
+
'web': {
|
| 50 |
+
'stype': 'xpath',
|
| 51 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//div[2]/a'
|
| 52 |
+
},
|
| 53 |
+
'tipoTramite1': {
|
| 54 |
+
'stype': 'xpath',
|
| 55 |
+
'value': '//div[@id="tab-0"]/span[contains(@class, "sm:text-base")]'
|
| 56 |
+
},
|
| 57 |
+
'tipoTramite2': {
|
| 58 |
+
'stype': 'xpath',
|
| 59 |
+
'value': '//div[@id="tab-1"]/span[contains(@class, "sm:text-base")]'
|
| 60 |
+
|
| 61 |
+
},
|
| 62 |
+
'botonIniciarTramiteEnLinea': {
|
| 63 |
+
'stype': 'xpath',
|
| 64 |
+
'value': '//span[@class="text-base sm:text-lg"][text()="Iniciar trámite en línea"]'
|
| 65 |
+
},
|
| 66 |
+
'queNecesitoText': {
|
| 67 |
+
'stype': 'xpath',
|
| 68 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="¿Qué necesito?"]/../div',
|
| 69 |
+
},
|
| 70 |
+
'comoYDondeTexto': {
|
| 71 |
+
'stype': 'xpath',
|
| 72 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="¿Cómo y dónde hago el trámite?"]/../div'
|
| 73 |
+
},
|
| 74 |
+
'direccionesTramite': {
|
| 75 |
+
# pueden haber multiples elementos
|
| 76 |
+
'stype': 'xpath',
|
| 77 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="Direcciones donde se realiza este trámite"]/../div//div[@role="tablist"]//div[@class="el-collapse-item__content"]/div'
|
| 78 |
+
},
|
| 79 |
+
'masInfo': {
|
| 80 |
+
'stype': 'xpath',
|
| 81 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="Más información"]/../div'
|
| 82 |
+
},
|
| 83 |
+
'ultimaActualizacion': {
|
| 84 |
+
'stype': 'xpath',
|
| 85 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="Más información"]/..//div/span[contains(text(),"Última actualización de la Información:")]/..'
|
| 86 |
+
},
|
| 87 |
+
'observaciones': {
|
| 88 |
+
# podria no existir
|
| 89 |
+
'stype': 'xpath',
|
| 90 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()="Más información"]/..//div/span[contains(text(),"Observaciones:")]/..'
|
| 91 |
+
},
|
| 92 |
+
'costoTexto': {
|
| 93 |
+
# podria no existir
|
| 94 |
+
'stype': 'xpath',
|
| 95 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()=" Costo del Trámite"]/../div'
|
| 96 |
+
},
|
| 97 |
+
'costoMontos': {
|
| 98 |
+
# podria no existir
|
| 99 |
+
'stype': 'xpath',
|
| 100 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()=" Costo del Trámite"]/../div//span[text()="Monto:"]/..'
|
| 101 |
+
},
|
| 102 |
+
'costoFormas': {
|
| 103 |
+
# podria no existir
|
| 104 |
+
'stype': 'xpath',
|
| 105 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()=" Costo del Trámite"]/../div//span[text()="Forma de pago:"]/..'
|
| 106 |
+
},
|
| 107 |
+
'costoConceptos': {
|
| 108 |
+
# podria no existir
|
| 109 |
+
'stype': 'xpath',
|
| 110 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()=" Costo del Trámite"]/../div//span[text()="Concepto de pago:"]/..'
|
| 111 |
+
},
|
| 112 |
+
'costoCtasBancarias': {
|
| 113 |
+
'stype': 'xpath',
|
| 114 |
+
'value': '//div[@class="animate-paragraph"]/h2[text()=" Costo del Trámite"]/../div//span[contains(text(),"N° Cuenta Bancaria")]/..'
|
| 115 |
+
},
|
| 116 |
+
'rateYellow': {
|
| 117 |
+
# podria no existir
|
| 118 |
+
'stype': 'xpath',
|
| 119 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//span[@class="el-rate__item"]/i[@style="color:#F3C800;"]'
|
| 120 |
+
},
|
| 121 |
+
'rateRed': {
|
| 122 |
+
# podria no existir
|
| 123 |
+
'stype': 'xpath',
|
| 124 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//span[@class="el-rate__item"]/i[@style="color:#FA0D00;"]'
|
| 125 |
+
},
|
| 126 |
+
'rateGreen': {
|
| 127 |
+
# podria no existir
|
| 128 |
+
'stype': 'xpath',
|
| 129 |
+
'value': '//div[@class="flex justify-between flex-col sm:flex-row"]//span[@class="el-rate__item"]/i[@style="color:#5DD90F;"]'
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
src/scraper.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This is part of gobbo-datos
|
| 3 |
+
Copyright Rodrigo Garcia 2025
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import traceback
|
| 7 |
+
from playwright.async_api import async_playwright
|
| 8 |
+
|
| 9 |
+
from src.locators import locators
|
| 10 |
+
from src.common.custom_logger import CustomLogger
|
| 11 |
+
from src.common.selectors import get_selector_value, get_locator, is_element_located
|
| 12 |
+
from src.common.time import random_sleep, today_yyyymmdd
|
| 13 |
+
from src.common.csv import csv_write_headers, append_to_csv, csv_columnnames_exist
|
| 14 |
+
from typing import List, Dict
|
| 15 |
+
|
| 16 |
+
LOGGER = CustomLogger('gob.bo scraper ')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class GobboScrapper:
|
| 20 |
+
"""Class that helps scraping gob.bo"""
|
| 21 |
+
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
width=1280,
|
| 25 |
+
height=800,
|
| 26 |
+
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
| 27 |
+
home_page='https://www.gob.bo/'
|
| 28 |
+
|
| 29 |
+
):
|
| 30 |
+
self.width = width
|
| 31 |
+
self.height = height
|
| 32 |
+
self.user_agent = user_agent
|
| 33 |
+
self.home_page = home_page
|
| 34 |
+
self.page = None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
async def init(self, p):
|
| 38 |
+
browser = await p.chromium.launch(headless=False)
|
| 39 |
+
|
| 40 |
+
context = await browser.new_context(
|
| 41 |
+
viewport={'width': self.width, 'height': self.height},
|
| 42 |
+
user_agent=self.user_agent,
|
| 43 |
+
)
|
| 44 |
+
self.page = await context.new_page()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
async def goto_home(self):
|
| 48 |
+
try:
|
| 49 |
+
await self.page.goto(self.home_page, wait_until="networkidle", timeout=120000)
|
| 50 |
+
except Exception as e:
|
| 51 |
+
LOGGER.error(LOGGER.format_exception(e))
|
| 52 |
+
raise e
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
async def enter_category(self, category: str):
|
| 56 |
+
"""Goes to the main page and loads the give category
|
| 57 |
+
"""
|
| 58 |
+
await self.goto_home()
|
| 59 |
+
await random_sleep(2, 5.5)
|
| 60 |
+
await self.page.locator(get_locator(locators['categorias']['linkPorNombre'], category)).click()
|
| 61 |
+
await random_sleep(1, 2.2)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
async def get_procedure_elements(self) -> List:
|
| 65 |
+
"""Gets the list of procedure elements
|
| 66 |
+
"""
|
| 67 |
+
try:
|
| 68 |
+
elements = await self.page.locator(get_locator(locators['listaTramites']['linkPorTramite'])).all()
|
| 69 |
+
return elements
|
| 70 |
+
except Exception as e:
|
| 71 |
+
LOGGER.error("Can't get procedures links.")
|
| 72 |
+
LOGGER.error(LOGGER.format_exception(e))
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
async def get_procedures_links(self) -> List[str]:
|
| 76 |
+
"""Get all links of procedures"""
|
| 77 |
+
links = []
|
| 78 |
+
try:
|
| 79 |
+
elements = await self.page.locator(get_locator(locators['listaTramites']['linkPorTramite'])).all()
|
| 80 |
+
for element in elements:
|
| 81 |
+
link_procedure = element.get_attribute("href")
|
| 82 |
+
links.append(f'{self.home_page}/{link_procedure}')
|
| 83 |
+
except Exception as e:
|
| 84 |
+
LOGGER.error("Can't get procedures links.")
|
| 85 |
+
LOGGER.error(LOGGER.format_exception(e))
|
| 86 |
+
|
| 87 |
+
return link
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
async def get_text_from_all_elements(self, locator):
|
| 91 |
+
"""Gets the text from all elements that matches the locator.
|
| 92 |
+
When there are multiple elements the text is concat with ,
|
| 93 |
+
If no element is found returns an empty string
|
| 94 |
+
"""
|
| 95 |
+
text = ''
|
| 96 |
+
if await is_element_located(self.page, locator):
|
| 97 |
+
web_elements = await self.page.locator(get_locator(locator)).all()
|
| 98 |
+
if len(web_elements) == 1:
|
| 99 |
+
return await web_elements[0].inner_text()
|
| 100 |
+
|
| 101 |
+
for web_element in web_elements:
|
| 102 |
+
text += await web_element.inner_text() + ','
|
| 103 |
+
return text
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
async def scrape_procedure_by_url(self, url) -> Dict:
|
| 107 |
+
"""Examines the current page that should be a procedure and gets
|
| 108 |
+
the data by scraping it.
|
| 109 |
+
|
| 110 |
+
#TODO: Agregar duracion (en mas informacion)
|
| 111 |
+
|
| 112 |
+
Returns:
|
| 113 |
+
Dictionary with procedure data
|
| 114 |
+
"""
|
| 115 |
+
LOGGER.debug(f'Scraping Procedure {url}')
|
| 116 |
+
try:
|
| 117 |
+
await self.page.goto(url, wait_until="networkidle", timeout=120000)
|
| 118 |
+
except Exception as e:
|
| 119 |
+
LOGGER.error(LOGGER.format_exception(e))
|
| 120 |
+
raise e
|
| 121 |
+
|
| 122 |
+
procedure = {}
|
| 123 |
+
procedure['titulo'] = await self.get_text_from_all_elements(locators['tramites']['titulo'])
|
| 124 |
+
LOGGER.debug(f' Title: {procedure["titulo"]}.')
|
| 125 |
+
procedure['institucion'] = await self.get_text_from_all_elements(
|
| 126 |
+
locators['tramites']['institucion']
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
procedure['descripcion'] = await self.get_text_from_all_elements(
|
| 130 |
+
locators['tramites']['descripcion']
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
procedure['institucion'] = await self.get_text_from_all_elements(
|
| 134 |
+
locators['tramites']['institucion'])
|
| 135 |
+
|
| 136 |
+
procedure['contacto'] = await self.get_text_from_all_elements(
|
| 137 |
+
locators['tramites']['contacto'])
|
| 138 |
+
|
| 139 |
+
procedure['web'] = await self.get_text_from_all_elements(
|
| 140 |
+
locators['tramites']['web'])
|
| 141 |
+
|
| 142 |
+
procedure['institucion'] = await self.get_text_from_all_elements(
|
| 143 |
+
locators['tramites']['institucion']
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
procedure['es_presencial'] = 0
|
| 147 |
+
procedure['es_en_linea'] = 0
|
| 148 |
+
|
| 149 |
+
tipoTramite1 = await self.get_text_from_all_elements(
|
| 150 |
+
locators['tramites']['tipoTramite1'])
|
| 151 |
+
if tipoTramite1.endswith('Presencial') is True:
|
| 152 |
+
procedure['es_presencial'] = 1
|
| 153 |
+
if tipoTramite1.endswith('Línea') is True:
|
| 154 |
+
procedure['es_en_linea'] = 1
|
| 155 |
+
else:
|
| 156 |
+
tipoTramite2 = await self.get_text_from_all_elements(
|
| 157 |
+
locators['tramites']['tipoTramite2'])
|
| 158 |
+
if tipoTramite2.endswith('Presencial') is True:
|
| 159 |
+
procedure['es_presencial'] = 1
|
| 160 |
+
if tipoTramite2.endswith('Línea') is True:
|
| 161 |
+
procedure['es_en_linea'] = 1
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
procedure['requisitos'] = await self.get_text_from_all_elements(
|
| 165 |
+
locators['tramites']['queNecesitoText'])
|
| 166 |
+
|
| 167 |
+
procedure['procedimiento'] = await self.get_text_from_all_elements(
|
| 168 |
+
locators['tramites']['comoYDondeTexto'])
|
| 169 |
+
|
| 170 |
+
procedure['num_ubicaciones'] = 0
|
| 171 |
+
procedure['ubicaciones'] = await self.get_text_from_all_elements(
|
| 172 |
+
locators['tramites']['direccionesTramite'])
|
| 173 |
+
ubicaciones_elements = await self.page.locator(
|
| 174 |
+
get_locator(locators['tramites']['direccionesTramite'])
|
| 175 |
+
).all()
|
| 176 |
+
procedure['num_ubicaciones'] = len(ubicaciones_elements)
|
| 177 |
+
|
| 178 |
+
procedure['info_adicional'] = await self.get_text_from_all_elements(
|
| 179 |
+
locators['tramites']['masInfo'])
|
| 180 |
+
|
| 181 |
+
procedure['ultima_actualizacion'] = await self.get_text_from_all_elements(
|
| 182 |
+
locators['tramites']['ultimaActualizacion'])
|
| 183 |
+
|
| 184 |
+
procedure['observaciones'] = await self.get_text_from_all_elements(
|
| 185 |
+
locators['tramites']['observaciones'])
|
| 186 |
+
|
| 187 |
+
procedure['costo_descripcion'] = await self.get_text_from_all_elements(
|
| 188 |
+
locators['tramites']['costoTexto'])
|
| 189 |
+
|
| 190 |
+
procedure['costo_montos'] = await self.get_text_from_all_elements(
|
| 191 |
+
locators['tramites']['costoMontos'])
|
| 192 |
+
|
| 193 |
+
procedure['costo_formas'] = await self.get_text_from_all_elements(
|
| 194 |
+
locators['tramites']['costoFormas'])
|
| 195 |
+
|
| 196 |
+
procedure['costo_conceptos'] = await self.get_text_from_all_elements(
|
| 197 |
+
locators['tramites']['costoConceptos'])
|
| 198 |
+
|
| 199 |
+
procedure['costo_ctas_bancarias'] = await self.get_text_from_all_elements(
|
| 200 |
+
locators['tramites']['costoCtasBancarias'])
|
| 201 |
+
|
| 202 |
+
r_green_elements = await self.page.locator(
|
| 203 |
+
get_locator(locators['tramites']['rateGreen'])).count()
|
| 204 |
+
r_yellow_elements = await self.page.locator(
|
| 205 |
+
get_locator(locators['tramites']['rateYellow'])).count()
|
| 206 |
+
r_red_elements = await self.page.locator(
|
| 207 |
+
get_locator(locators['tramites']['rateRed'])).count()
|
| 208 |
+
procedure['calificacion'] = r_green_elements + r_yellow_elements + r_red_elements
|
| 209 |
+
|
| 210 |
+
return procedure
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
async def scrape_entire_category(self, category: str, save_to_file=None) -> List[Dict]:
|
| 214 |
+
"""Gets all procedures data of the given category.
|
| 215 |
+
Enters to each of procedures by click to them and returning to the
|
| 216 |
+
original page.
|
| 217 |
+
|
| 218 |
+
Parameters:
|
| 219 |
+
category (str): Name of the category from the main page
|
| 220 |
+
|
| 221 |
+
Returns:
|
| 222 |
+
Dictionary with Procedures data
|
| 223 |
+
"""
|
| 224 |
+
# 1. Enters to the category
|
| 225 |
+
await self.enter_category(category)
|
| 226 |
+
|
| 227 |
+
procedures = []
|
| 228 |
+
|
| 229 |
+
pages = 0
|
| 230 |
+
LOGGER.info(f'Starting category {category}----------------------------------------------')
|
| 231 |
+
procedure_urls = []
|
| 232 |
+
while True:
|
| 233 |
+
LOGGER.info(f'----------- {category} - Page: {pages}')
|
| 234 |
+
|
| 235 |
+
# Get procedures of the current page
|
| 236 |
+
elements = await self.get_procedure_elements()
|
| 237 |
+
# Scraping every procedure element
|
| 238 |
+
|
| 239 |
+
for i, procedure_element in enumerate(elements):
|
| 240 |
+
await elements[i].scroll_into_view_if_needed()
|
| 241 |
+
procedure_urls.append(await elements[i].get_attribute('href'))
|
| 242 |
+
|
| 243 |
+
# Next page
|
| 244 |
+
if await is_element_located(self.page, locators['listaTramites']['pagSiguienteBtn']):
|
| 245 |
+
LOGGER.info(f'Forwarding page {pages} \n\n')
|
| 246 |
+
next_btn = self.page.locator(
|
| 247 |
+
get_locator(locators['listaTramites']['pagSiguienteBtn'])
|
| 248 |
+
)
|
| 249 |
+
await next_btn.scroll_into_view_if_needed()
|
| 250 |
+
await random_sleep(2, 4)
|
| 251 |
+
await next_btn.click()
|
| 252 |
+
pages += 1
|
| 253 |
+
await random_sleep(0.4, 2)
|
| 254 |
+
else:
|
| 255 |
+
LOGGER.debug('Next page button not found. --------------------------------------')
|
| 256 |
+
LOGGER.info(f'Total of {len(procedures)} - Category: {category} ({pages} pages)')
|
| 257 |
+
break
|
| 258 |
+
|
| 259 |
+
LOGGER.info('Getting procedures data.')
|
| 260 |
+
|
| 261 |
+
for url in procedure_urls:
|
| 262 |
+
# scrape procedure page
|
| 263 |
+
#procedure = await self.scrape_current_procedure_page()
|
| 264 |
+
procedure = await self.scrape_procedure_by_url(self.home_page + url)
|
| 265 |
+
procedure['url'] = self.home_page + url
|
| 266 |
+
procedure['categoria'] = category
|
| 267 |
+
await random_sleep(0.5, 1.5)
|
| 268 |
+
procedures.append(procedure)
|
| 269 |
+
if save_to_file is not None:
|
| 270 |
+
LOGGER.debug(f'Saving procedure to file {save_to_file}')
|
| 271 |
+
csv_headers = list(procedure.keys())
|
| 272 |
+
if csv_columnnames_exist(save_to_file, csv_headers) is False:
|
| 273 |
+
csv_write_headers(save_to_file, csv_headers)
|
| 274 |
+
append_to_csv(procedure, csv_headers, save_to_file)
|
| 275 |
+
LOGGER.debug('Added to csv.')
|
| 276 |
+
LOGGER.debug(f'Saved procedures up to now: {len(procedures)}')
|
| 277 |
+
|
| 278 |
+
return procedures
|