我是网络爬虫和尝试从站点(https://www.tradingview.com/symbols/EURCHF/?exchange=OANDA)检索标题名称和值的新手
我正在使用BeautifulSoup的find_all函数,该函数查找标题行但返回值的空列表。我的代码如下所示:
Socket.io
为什么返回空列表。 在检查现场数据时,它将“ Info”显示为tabValue-3iOTI9jm 我已经拍摄了截图,显示在这里 Inspect ScreenShot
运行我的代码后,name1被打印出来,但是val1显示为空列表。结果显示在这里 Results
答案 0 :(得分:0)
更新:这是对Back-End
API
import requests
data = {"symbols": {"tickers": ["FX_IDC:EURCHF"], "query": {"types": ["forex"]}}, "columns": ["Recommend.All", "RSI", "RSI[1]", "Stoch.K", "Stoch.D", "Stoch.K[1]", "Stoch.D[1]", "CCI20", "CCI20[1]", "ADX", "ADX+DI", "ADX-DI", "ADX+DI[1]", "ADX-DI[1]", "AO", "AO[1]", "Mom", "Mom[1]", "MACD.macd", "MACD.signal",
"Rec.Stoch.RSI", "Stoch.RSI.K", "Rec.WR", "W.R", "Rec.BBPower", "BBPower", "Rec.UO", "UO", "EMA5", "close", "SMA5", "EMA10", "SMA10", "EMA20", "SMA20", "EMA30", "SMA30", "EMA50", "SMA50", "EMA100", "SMA100", "EMA200", "SMA200", "Rec.Ichimoku", "Ichimoku.BLine", "Rec.VWMA", "VWMA", "Rec.HullMA9", "HullMA9"]}
r = requests.post(
"https://scanner.tradingview.com/forex/scan", json=data).json()
print(r)
输出:
{'data': [{'s': 'FX_IDC:EURCHF', 'd': [-0.3474026, 40.20328953, 40.7342841, 24.71794872, 32.35897436, 30.23076923, 40.12820513, -71.9887128, -68.01055011, 16.51125049, 14.84157898, 16.77182105, 14.90478566, 16.84324816, -0.00283482, -0.00251176, -0.00017, 0.00098, -0.00161929, -0.00171414, 0, 45.887686, 0, -78.69230769, 0, -0.00475522, 0, 45.51407259, 1.05654604, 1.05526, 1.056942, 1.05734726, 1.058608, 1.05837338, 1.057454, 1.0597646, 1.059502, 1.06326959, 1.0621026, 1.07175293, 1.0747255, 1.08482787, 1.08547945, 0, 1.061735, None, None, 1, 1.05488111]}], 'totalCount': 1}
好吧,TradingView
会在页面加载后通过JavaScript
动态加载。因此,bs4
将无法在空中渲染JavaScript
。.
您应该考虑直接使用API。或者,您可以使用selenium
方法。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)
driver.get("https://www.tradingview.com/symbols/EURCHF/?exchange=OANDA")
element = driver.find_element_by_class_name("tabValue-3iOTI9jm").text
print(element)
driver.quit()
输出:
1.05613