我是 http 新手,需要帮助。我正在尝试在craigslist中填写搜索表格,以便获得指向如果我手动填写表格通常会获得的页面的链接。通过查看源代码,我发现了这个表格:
<form id="search" action="/search/" method="GET">
<div>search craigslist</div>
<input type="hidden" name="areaID" value="372">
<input type="hidden" name="subAreaID" value="">
<input id="query" name="query" autocorrect="off" autocapitalize="off"><br>
<select id="catAbb" name="catAbb">
<option value="ccc">community</option>
<option value="eee">events</option>
<option value="ggg">gigs</option>
<option value="hhh">housing</option>
<option value="jjj">jobs</option>
<option value="ppp">personals</option>
<option value="res">resumes</option>
<option value="sss" selected="selected">for sale</option>
<option value="bbb">services</option>
</select>
<input id="go" type="submit" value=">">
</form>
所以我写了这段代码来填写表格:
import urllib,httplib
conn = httplib.HTTPConnection("auburn.craigslist.org")
params = urllib.urlencode({'query': 'english tutor', 'catAbb': 'bbb'})
conn.request("GET","/search",params)
response = conn.getresponse()
print response.read()
我不确定所有的事情,例如我如何指定我要填写哪个表格?我假设它是通过在表单的“操作”中指定“\search”,但它真的应该在 httplib.request 的“url”参数中吗?无论如何,我没有得到我想要的结果页面的 url,而是得到了这个 html 页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>auburn craigslist search</title>
<blockquote>
<b>You did not select a category to search.</b>
</blockquote>
但我很确定我确实选择了一个类别。我该怎么办?谢谢!