Thursday 15 August 2013

use python requests library to post data to search box -



use python requests library to post data to search box -

i trying figure out, in order post info right form, key, , value. in opinion, think html tag's id, has method get, key. , text set in text box should value.

<form id="searchbox_form" class="searchbox_form form man" method="get" action="/submit_search/" autocomplete="off">

so question is, how webpage html after putting text in search box? give thanks guys, here's code

import requests r = requests.post("http://www.trulia.com/homepage.php?", data={'searchbox_form form man':'7420 westlake ter #1210 20817'}) open("test.html", "w") f: f.write(r.text.encode("utf-8"))

the form submitted using http get method , submitted url in action attribute of form. submitting query in http://www.trulia.com/submit_search/

now can approach this,

from urllib import urlencode import requests params = {'search': '7420 westlake ter #1210 20817'} search_url = 'http://www.trulia.com/submit_search/?' url = search_url + urlencode(params) r = requests.get(url) # desired response.

you can utilize firebug or developers tool see request.

python python-requests

No comments:

Post a Comment