我正试图从网站上抓取一张桌子,但我得到了NULL。
我如何获得桌子? 我在做什么错了?
import requests
from bs4 import BeautifulSoup
html = "https://traderslounge.in/implied-volatility-rank-nse-fno-stocks/" #link that has to be scrapped
response = requests.get(url) # before we feed it to request to parse
response.status_code
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find_all("th")
list_of_rows = []
for row in table.findAll("td"):
list_of_cells = []
for cell in row.findAll(["th","td"]):
text = cell.text
print(text)
list_of_cells.append(text)
list_of_rows.append(list_of_cells)
for item in list_of_rows:
print(' '.join(item))
答案 0 :(得分:2)
此站点的表内容是从外部API检索的:
https://traderslounge.in/FNO/ivrank/ivranktable.txt
您可以使用:
import requests
r = requests.get('https://traderslounge.in/FNO/ivrank/ivranktable.txt')
print(r.json()["data"])