我无法获得 BeautifulSoup 命令的分辨率
I cant get the resulation of BeautifulSoup commant
我已经开始使用 BeautifulSoup yet.I 制作了这样的脚本:
import bs4
import requests
from bs4 import BeautifulSoup
def parsePrice():
r=requests.get('https://steamcommunity.com/market/listings/440/Mann%20Co.%20Supply%20Crate%20Key')
soup=bs4.BeautifulSoup(r.text,"xml")
price=soup.find_all('span',{'class':'market_commodity_orders_header_promote'})[0].find('span').text
return price
while True:
print('the current price: '+str(parsePrice()))
当我点击 运行 按钮时,它显示错误,
runfile('C:/Users/tuck/.spyder-py3/temp.py', wdir='C:/Users/tuck/.spyder-py3')
Traceback (most recent call last):
File "C:\Users\tuck\.spyder-py3\temp.py", line 15, in <module>
print('the current price: '+str(parsePrice()))
File "C:\Users\tuck\.spyder-py3\temp.py", line 11, in parsePrice
price=soup.find_all('span',{'class':'market_commodity_orders_header_promote'})[0].find('span').text
IndexError: list index out of range
所需输出的图像:
是的,内容是动态加载的,所以你可以先去做什么
chrome 开发人员并找到网络选项卡并转到 xhr 选项卡
然后刷新您的站点,现在您可以在名称选项卡中看到 link 存在
现在点击 links 并找到你的数据
所以它包含json数据现在你可以复制link的link地址
其中包含正确的信息,我还添加了图像以便更好地理解
import requests
from bs4 import BeautifulSoup
r=requests.get('https://steamcommunity.com/market/itemordershistogram?country=IN&language=english¤cy=1&item_nameid=1&two_factor=0')
main_data=r.json()
html=main_data['sell_order_summary']
soup=BeautifulSoup(html,"html.parser")
soup.text
输出:
'10079 for sale starting at .47'
图片:
我已经开始使用 BeautifulSoup yet.I 制作了这样的脚本:
import bs4
import requests
from bs4 import BeautifulSoup
def parsePrice():
r=requests.get('https://steamcommunity.com/market/listings/440/Mann%20Co.%20Supply%20Crate%20Key')
soup=bs4.BeautifulSoup(r.text,"xml")
price=soup.find_all('span',{'class':'market_commodity_orders_header_promote'})[0].find('span').text
return price
while True:
print('the current price: '+str(parsePrice()))
当我点击 运行 按钮时,它显示错误,
runfile('C:/Users/tuck/.spyder-py3/temp.py', wdir='C:/Users/tuck/.spyder-py3')
Traceback (most recent call last):
File "C:\Users\tuck\.spyder-py3\temp.py", line 15, in <module>
print('the current price: '+str(parsePrice()))
File "C:\Users\tuck\.spyder-py3\temp.py", line 11, in parsePrice
price=soup.find_all('span',{'class':'market_commodity_orders_header_promote'})[0].find('span').text
IndexError: list index out of range
所需输出的图像:
是的,内容是动态加载的,所以你可以先去做什么 chrome 开发人员并找到网络选项卡并转到 xhr 选项卡
然后刷新您的站点,现在您可以在名称选项卡中看到 link 存在 现在点击 links 并找到你的数据
所以它包含json数据现在你可以复制link的link地址 其中包含正确的信息,我还添加了图像以便更好地理解
import requests
from bs4 import BeautifulSoup
r=requests.get('https://steamcommunity.com/market/itemordershistogram?country=IN&language=english¤cy=1&item_nameid=1&two_factor=0')
main_data=r.json()
html=main_data['sell_order_summary']
soup=BeautifulSoup(html,"html.parser")
soup.text
输出:
'10079 for sale starting at .47'
图片: