目标: 我想使用Python,从“ https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=INR”中收集最近30天的平均值(Chrome浏览器上检查的HTML元素为“ 76.2664”)。
免责声明:我只是出于教育目的而放弃价值
我可以在Chrome浏览器中清楚地看到上述元素,但是无法使用BeautifulSoup渲染引擎进行读取。
下面是我到目前为止已创建的代码:
import requests, bs4
res = requests.get('https://www.xe.com/currencyconverter/convert/?Amount=1&From=USD&To=INR')
res.raise_for_status()
exampleSoup = bs4.BeautifulSoup(res.text,'html.parser')
elems = exampleSoup.select('div')
print(elems)
问题: 1.为什么元素在Chrome上可见但在HTML源代码中不可见? 2.我是否出于目的使用了正确的渲染引擎(beautifulsoup)? 3.我应该使用什么CSS选择器来获得最近30天的平均值?
答案 0 :(得分:0)
您可以在网络标签中看到它来自此端点
https://www.xe.com/api/stats.php?fromCurrency=USD&toCurrency=INR
在
下json['payload']['Last_30_Days']['average']
它明确指出自动提取违反了使用条款。