I am referring to the following question listed on stackoverflow: Scrapy, scrapping data inside a javascript
I am trying to replicate the answer to this question given by @Rho to learn how to scrape data from a javascript-generated form. The payload to the form seems to have changed since this question was posted so I have modified accordingly.
My code and output is as follows:
>>>scrapy shell https://www.mcdonalds.com.sg/locate-us/
2015-07-07 12:09:28+0800 [scrapy] INFO: Scrapy 0.24.6 started (bot: scrapybot)
.....
2015-07-07 12:09:28+0800 [default] INFO: Spider opened
2015-07-07 12:09:32+0800 [default] DEBUG: Crawled (200) <GET https://www.mcdonalds.com.sg/locate-us/> (referer: None)
....
>>> url = 'https://www.mcdonalds.com.sg/wp-admin/admin-ajax.php'
>>> payload = {'action':'store_locator_locations'}
>>> head = {'X-Requested-With':'XMLHttpRequest'}
>>> from scrapy.http import FormRequest
>>> req=FormRequest(url,formdata=payload,headers=head)
>>> fetch(req)
2015-07-07 12:12:24+0800 [default] DEBUG: Crawled (404) <POST https://www.mcdonalds.com.sg/wp-admin/admin-ajax.php> (referer: None)
Expected response is 200
, but as you can see above I am getting 404
error code.