Skip to content

Commit

Permalink
Merge pull request #448 from danieldotnl/submit_once
Browse files Browse the repository at this point in the history
Fix issue with unpacking result when submit_once
  • Loading branch information
danieldotnl authored Nov 11, 2024
2 parents a550eec + 54337ab commit 6b65d3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
21 changes: 12 additions & 9 deletions custom_components/multiscrape/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ async def get_content(self) -> str:

if self._form_submitter:
try:
result, self._cookies = await self._form_submitter.async_submit(resource)
self._form_variables = self._form_submitter.scrape_variables()

if result:
_LOGGER.debug(
"%s # Using response from form-submit as content for scraping.",
self._config_name,
)
return result
if self._form_submitter.should_submit is True:
result, self._cookies = await self._form_submitter.async_submit(resource)
self._form_variables = self._form_submitter.scrape_variables()

if result:
_LOGGER.debug(
"%s # Using response from form-submit as content for scraping.",
self._config_name,
)
return result
else:
_LOGGER.debug("%s # Skip submitting form", self._config_name)
except Exception as ex:
_LOGGER.error(
"%s # Exception in form-submit feature. Will continue trying to scrape target page.\n%s",
Expand Down
9 changes: 5 additions & 4 deletions custom_components/multiscrape/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ def notify_scrape_exception(self):
)
self._should_submit = True

@property
def should_submit(self):
"""Return the form variables."""
return self._should_submit

async def async_submit(self, main_resource):
"""Submit the form."""
if not self._should_submit:
_LOGGER.debug("%s # Skip submitting form", self._config_name)
return

_LOGGER.debug("%s # Starting with form-submit", self._config_name)
input_fields = {}
action, method = None, None
Expand Down

0 comments on commit 6b65d3a

Please sign in to comment.