【发布时间】:2018-09-01 15:33:48
【问题描述】:
我希望从下面的 url 中提取表格数据。具体来说,我想提取第一列中的数据。当我运行下面的代码时,第一列中的数据会重复多次。如何让值在表格中只显示一次?
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen('http://www.pythonscraping.com/pages/page3.html').read()
soup = BeautifulSoup(html, 'lxml')
table = soup.find('table',{'id':'giftList'})
rows = table.find_all('tr')
for row in rows:
data = row.find_all('td')
for cell in data:
print(data[0].text)
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup python-requests