在网站上搜索python和请求

时间:2015-07-16 01:22:37

标签: python-3.x python-requests

搜索字段的输入:

<form class="search-form"     
action="http://services.runescape.com/m=itemdb_rs/results#main-search" method="post">
<input class="text" placeholder="Search..." name="query" required="" type="search"> 
<input class="search-submit" value="Search" type="submit">

我有这个脚本,但它没有执行搜索我...任何想法为什么?

import requests
from bs4 import BeautifulSoup
url = 'http://services.runescape.com/m=itemdb_rs/'
body = {'Search':'rune'}
s = requests.Session()
log = s.get(url)
with requests.Session() as s:
    con = s.post('http://services.runescape.com/m=itemdb_rs/results#main-search', data=body)
    print (con.text)

1 个答案:

答案 0 :(得分:1)

两个小修正,代码对我有用:

import requests

body = {'query':'rune'} # <-- use 'query' not `Search'

con = requests.post('http://services.runescape.com/m=itemdb_rs/results#main-search', data=body)
print (con.content) # <-- print .content not .text