From f8030ed1f3364a1ba158fe2954e90ba2147c958d Mon Sep 17 00:00:00 2001 From: trevineju Date: Sun, 12 Jan 2025 20:05:17 -0300 Subject: [PATCH] =?UTF-8?q?Renomeia=20m=C3=A9todos=20e=20complementa=20for?= =?UTF-8?q?mdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_collection/gazette/spiders/se_aracaju.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/data_collection/gazette/spiders/se_aracaju.py b/data_collection/gazette/spiders/se_aracaju.py index b28459e6f..fae7135e4 100644 --- a/data_collection/gazette/spiders/se_aracaju.py +++ b/data_collection/gazette/spiders/se_aracaju.py @@ -21,19 +21,20 @@ def start_requests(self, cookiejar=None): "http://sga.aracaju.se.gov.br:5011/legislacao/faces/diario_form_pesq.jsp", meta={"cookiejar": cookiejar} if cookiejar is not None else {}, dont_filter=True, + callback=self.make_mandatory_post_request, ) - def parse(self, response): + def make_mandatory_post_request(self, response): mesano_param = response.css("[value=mesano]::attr(name)").get() yield scrapy.FormRequest.from_response( response, formdata={mesano_param: "mesano"}, - callback=self.parse_search_by_month_and_year, + callback=self.start_session_ids, dont_filter=True, meta={"cookiejar": response.meta.get("cookiejar")}, ) - def parse_search_by_month_and_year(self, response): + def start_session_ids(self, response): if not response.meta.get("cookiejar", False): rule_start_date = datetime.date( self.start_date.year, self.start_date.month, 1 @@ -57,6 +58,10 @@ def make_year_month_request(self, response, formdata=None): container_id = response.css("select::attr(onchange)").re_first( r"containerId\':\'(.+)\'" ) + form_param = response.css("form").attrib["id"] + + mesano_param = response.css("input")[2].attrib["id"] + mes_param = response.xpath( "//td[contains(./span//text(), 'Mês')]/following-sibling::td//select/@name" ).get() @@ -70,8 +75,11 @@ def make_year_month_request(self, response, formdata=None): response, formdata={ "AJAXREQUEST": container_id, + form_param: form_param, + mesano_param: "mesano", ano_param: str(year), mes_param: str(month), + # view_param search_button_param: search_button_param, }, meta={"cookiejar": cookiejar},