Skip to content

Commit

Permalink
Renomeia métodos e complementa formdata
Browse files Browse the repository at this point in the history
  • Loading branch information
trevineju committed Jan 12, 2025
1 parent a13d016 commit f8030ed
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions data_collection/gazette/spiders/se_aracaju.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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},
Expand Down

0 comments on commit f8030ed

Please sign in to comment.