简体   繁体   English

使用 python 抓取 html 表

[英]Scraping html table using python

I am trying to scrape a table through from a website but i am getting NULL.我正在尝试从网站上抓取一张桌子,但我得到的是 NULL。

How can i get the table?我怎样才能拿到桌子? What am i doing wrong?我究竟做错了什么?

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))

The table content of this site is retrieved from an external API:本站表内容取自外部API:

https://traderslounge.in/FNO/ivrank/ivranktable.txt https://traderslounge.in/FNO/ivrank/ivranktable.txt

You can get the result using:您可以使用以下方法获得结果:

import requests

r = requests.get('https://traderslounge.in/FNO/ivrank/ivranktable.txt')

print(r.json()["data"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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