Having worked with Selenium, I'm in the process of transitioning my project to Scrapy, but I've encountered some challenges. I've explored the documentation, but I haven't found a solution yet.
input_element = driver.find_element(By.ID, "location-typeahead-home-input")
input_element.send_keys("Boston Park Plaza")
time.sleep(2)
button_xpath = "//main[@id='main-content']//button"
button_elements = driver.find_elements(By.XPATH, button_xpath)
if len(button_elements) >= 2:
second_button = button_elements[1]
second_button.click()
else:
button_elements[0].click()`
I've experimented with the sample code, but it seems to require a form, which is not available in this context.
input_element = response.css("input#location-typeahead-home-input")
input_element_value = "Boston Park Plaza"
button = response.xpath("//main[@id='main-content']//button")
yield scrapy.FormRequest.from_response(
response,
formdata={input_element.attrib['name']: input_element_value},
formname=None,
clickdata={'xpath': "//main[@id='main-content']//button"},
callback=self.after_search
)`
I've attempted to transition my Selenium project to Scrapy and encountered issues with input field interactions and button clicks.
The simplest answer is: You can't press buttons using Scrapy!
You need to understand how data is being sent to the server (i.e., POST method) and then you have to narrate things just as the browser does.