简体   繁体   中英

how to extract a certain number from a website in python

I need to make a bot for a client that gets data from http://backpack.tf/stats/Unique/AWPer%20Hand/Tradable/Craftable and does some research.

On the top of the website you see the recomended price (3 ref) and if you scroll down you can see what people are actaully selling them for.

I need to see if what there selling them for is less then the recomended price. I have inspected the element and found that each listing uses a class called "media listing" followed by a random ID. Where do i go from here?

I would suggest reading the BeautifulSoup documentation , but this should give you a good idea of what you want to do:

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'})])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM