【发布时间】:2018-02-03 23:26:23
【问题描述】:
我已经访问了表格并将信息带入 python,但我无法遍历列名和行名以使用正确的相关值填充表格。如何遍历第一行以提取第 col 标头值?
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
req = Request('https://www.mrci.com/special/corr030.php',headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req, context = ctx).read()
soup = BeautifulSoup(webpage, 'lxml') # Parse the HTML as a string
table = soup.find_all('table')[2] # Grab the first table
for row in table.find_all('tr')[1:]:
print(row)
有人对我如何将整个表格拉入熊猫数据框有任何见解吗?
【问题讨论】:
标签: python pandas beautifulsoup