如何使用python从网页中抓取表格?

时间:2019-06-01 15:37:21

标签: python beautifulsoup

我正在尝试从网页抓取数据。.使用beautifulsoup和请求..但我收到错误列表索引超出范围..如何解决此错误..任何帮助将不胜感激..在此先感谢..

from bs4 import BeautifulSoup
import requests
import time

url = 'https://etrain.info/in?PNR=6429866568'
response = requests.get(url)
time.sleep(1)

soup = BeautifulSoup(response.content, "html.parser")
Table = soup.find_all('table', class_='nocps fullw bx2s rnd5')

Table = Table[0]

for row in Table.find_all('tr'):
    for cell in row.find_all('td'):
        print(cell.text)

0 个答案:

没有答案