0
我有這段代碼,我可以在Python 2.7的網站上搜索名爲「ctable」的所有表。但我想離開最後的1-2張桌子。 我該怎麼做?我如何才能離開最後一張網絡報紙表?
soup = BeautifulSoup(x, 'lxml')
datatable=[]
for ctable in soup.find_all('table', "ctable"):
for record in ctable.find_all('tr'):
temp_data = []
for data in record.find_all('td'):
temp_data.append(data.text.encode('latin-1'))
datatable.append(temp_data)
output.writerows(datatable)
謝謝你,這是工作循環! – tardos93