[英]All the rows expect 0th Row
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
我正在尋找一種方法來使所有行都期望第0行? 我知道如何獲取第0或任何特定的行..但是我希望每個'tr'標簽/行都期望第0。
有什么建議么
find_all()
返回一個ResultSet
實例,該實例是您可以切片的列表的子類:
table.find_all('tr')[1:]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.