【发布时间】:2019-09-18 16:49:45
【问题描述】:
我是网络抓取的新手,我正在尝试在登录后抓取网站上的表格数据。我希望将第 2 列乘以 10。
目前表格正在写入 csv,但我真正想要的工作是将第二列乘以 10 并写入 csv
我试过的是:
r2=session.post("http://www.example.com")
soup = BeautifulSoup(r2.text, "html.parser")
csvFile=open('Table.csv','w')
output = csv.writer(csvFile)
for table in soup.find_all('table')[5:]:
for row in table.find_all('tr'):
col = map(cell_text, row.find_all(re.compile('t[dh]')))
output.writerow(col)
output.writerow([])
csvFile.close()
例如,如果我在网站中有一个包含数据的表格:
Time Pressure Mass Temp
0.00 1.01 21 23.09
1.00 2.0908 21.1 10.07
2.0 2.8666 22.3 13.6
0.555 2.6545 2.4 32.56
The data for writing csv file should be:
0.00 10.1 21 23.09
1.00 20.908 21.1 10.07
2.0 28.666 22.3 13.6
0.555 26.545 2.4 32.56
怎么做?
【问题讨论】:
标签: python csv web-scraping html-table beautifulsoup