如何使用python beautiful soup从网页网址中删除表格数据?

时间:2017-05-12 09:33:36

标签: python-3.x beautifulsoup lxml

这是写入从网页获取数据的代码:

导入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的值

0 个答案:

没有答案