这是写入从网页获取数据的代码:
导入urllib.request import urllib 来自bs4 import BeautifulSoup
def make_soup(url):
req=urllib.request.Request(url,headers={'User-Agent': 'Mozilla/5.0'})
thepage=urllib.request.urlopen(req)
soupdata=BeautifulSoup(thepage,'html5lib')
return soupdata
soup=make_soup("https://www.nseindia.com/live_market/dynaContent/live_analysis/top_gainers_losers.htm?cat=G")
t=soup.findAll('table')[0]
for record in t.findAll('tr'):
print(record.td.text)
'''
for record in t.findAll('tr'):
for data in record.findAll('td'):
print(data.text)
'''
但是这段代码只取出了第一个tr。如何获得剩余tr的值