如何在网页上搜索搜索字段?

时间:2016-09-20 19:30:40

标签: python web-scraping

如何打开网页,例如:http://www.futbin.com/

...并使用页面上的搜索字段搜索项目?

即。 “搜索玩家......”

1 个答案:

答案 0 :(得分:1)

您不需要抓取网页,它有直接搜索API

import requests
s = "Ronaldo"
r = requests.get("http://www.futbin.com/api?term={}".format(s))
r.json()

输出

[{u'club_image': u'/content/fifa16/img/clubs/243.png',
  u'full_name': u'Cristiano Ronaldo',
  u'id': u'38387',
  u'image': u'/content/fifa16/img/players/20801.png',
  u'nation_image': u'/content/fifa16/img/nation/38.png',
  u'position': u'LW',
  u'rare': u'1',
  u'rare_type': u'11',
  u'rating': u'99'},
...

修改

from bs4 import BeautifulSoup
import requests

r = requests.get("http://www.futbin.com/16/player/38387/cristiano-ronaldo")
soup = BeautifulSoup(r.text, "html.parser")
pslbin = soup.findAll("span", {'id': "pslbin"})[0].text.strip()
print(plsbin)