答案 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)