I have a clickable link on a dynamically created page, that looks like:
<td align="left"><a id="ucResultsGrid_X77" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ucResultsGrid$X77", "", false, "", "webProperty.aspx?stype=id&s=67&time=201606071553023&id=X77", false, true))" style="text-decoration:underline;">View Property</a></td><td align="right">X77</td>
After inspecting the page source, it appears that this submits to:
<form name="searchForm" method="post" action="./webSearch.aspx?cad&stype=id&s=67&time=201606071512012" id="searchForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/really long string />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['searchForm'];
if (!theForm) {
theForm = document.searchForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
I've been reading through http://harman-clarke.co.uk/answers/javascript-links-in-scrapy.php and http://cpuknows.com/2015/09/12/scrapy/ . from these and other sources (http://doc.scrapy.org/en/latest/faq.html#what-s-this-huge-cryptic-viewstate-parameter-used-in-some-forms and https://blog.scrapinghub.com/2016/04/20/scrapy-tips-from-the-pros-april-2016-edition/)
I've produced the following spider function:
def parse_third_request(self, response):
item = response.meta['item']
yield FormRequest.from_response(response,formname='searchForm',callback=self.parse_detail_page,meta={'item': item})
However I'm not clear on how to set the formdata dictionary mentioned in http://doc.scrapy.org/en/latest/topics/request-response.html#request-subclasses . In this case I'm clicking a link not filling a form.