如何从python中的网站中提取某个数字

时间:2015-07-13 01:35:45

标签: python html

我需要为从http://backpack.tf/stats/Unique/AWPer%20Hand/Tradable/Craftable获取数据的客户制作机器人并进行一些研究。

在网站的顶部,您会看到推荐的价格(3参考),如果您向下滚动,您可以看到人们出售它们的行为。

我需要看看出售它们的是否低于推荐价格。我检查过该元素,发现每个列表都使用了一个名为"媒体列表"然后是随机ID。我从哪里开始?

1 个答案:

答案 0 :(得分:1)

我建议您阅读BeautifulSoup documentation,但这可以让您对自己想做的事情有所了解:

from bs4 import BeautifulSoup
import requests

url = "http://backpack.tf/stats/Unique/AWPer%20Hand/Tradable/Craftable"
r = requests.get(url)

soup = BeautifulSoup(r.text)

curPrice = soup.find('h2').findNext('a').text

print 'The current price is: {0}'.format(curPrice)

print 'These are the prices they are being sold at: '
print '\n'.join([item.text for item in soup.find_all('span', attrs={'class': 'label label-black', 'data-tip': 'bottom'})])