1
from bs4 import BeautifulSoup
import urllib2
from lxml.html import fromstring
import re
import csv
import pandas as pd

wiki = "http://en.wikipedia.org/wiki/List_of_Test_cricket_records"
header = {'User-Agent': 'Mozilla/5.0'} #Needed to prevent 403 error on Wikipedia
req = urllib2.Request(wiki,headers=header)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page)

try:
    table = soup.find_all('table')[1]
except AttributeError as e:
    print 'No tables found, exiting'

#gets all the tr tags

try:
    rows = table.find_all('tr')
except AttributeError as e:
    print 'No table rows found, exiting'

#gets only the 0th row        

try:
    first = table.find_all('tr')[0]
except AttributeError as e:
    print 'No table row found, exiting'

#how to get all rows expect the 0th one??
try:
    allRows = table.find_all('tr')
except AttributeError as e:
    print 'No table row found, exiting'
print allRows

I am looking for a way to get all the rows expect the 0th row? I know how to get 0th or any particular row.. but I want every 'tr' tag/ row expect 0th.

Any suggestions

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Divya Jose
  • 389
  • 1
  • 4
  • 21

1 Answers1

4

find_all() returns a ResultSet instance which is a subclass of a list which you can slice:

table.find_all('tr')[1:]
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195