<div id="findet_1" name="findet_1" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="thc01 w160 gL_10 UC" > Standalone</td>
<td class="thc01 w160 gL_10 tar">Jun'16</td>
<td class="thc01 w160 gL_10 tar">Mar'16</td>
<td class="thc01 w160 gL_10 tar">Dec'15</td>
<td class="thc01 w160 gL_10 tar"><div class="PR20">Sep'15</div></td>
</tr>
<tr>
<td class="thc02 w160 gD_12" >Net Sales</td>
<td class="thc02 w160 gD_12 tar">16,339.70</td>
<td class="thc02 w160 gD_12 tar">15,589.40</td>
<td class="thc02 w160 gD_12 tar">15,065.00</td>
<td class="thc02 w160 gD_12 tar"><span class="PR20">14,824.50</span></td>
</tr>
<tr>
<td class="thc02 w160 gD_12" >Other Income</td>
<td class="thc02 w160 gD_12 tar">50.10</td>
<td class="thc02 w160 gD_12 tar">46.30</td>
<td class="thc02 w160 gD_12 tar">153.30</td>
<td class="thc02 w160 gD_12 tar"><span class="PR20">1,087.40</span></td>
</tr>
<tr>
<td class="thc02 w160 gD_12" >PBDIT</td>
<td class="thc02 w160 gD_12 tar">6,612.30</td>
<td class="thc02 w160 gD_12 tar">5,930.60</td>
<td class="thc02 w160 gD_12 tar">5,543.30</td>
<td class="thc02 w160 gD_12 tar"><span class="PR20">5,416.80</span></td>
</tr>
<tr>
<td class="thc02 w160 gD_12" >Net Profit</td>
<td class="thc02 w160 gD_12 tar">1,427.50</td>
<td class="thc02 w160 gD_12 tar">1,693.90</td>
<td class="thc02 w160 gD_12 tar">1,709.10</td>
<td class="thc02 w160 gD_12 tar"><span class="PR20">2,223.70</span></td>
</tr>
</table>
</div>
我正在试着读这张表。但无法做到这一点。我正在使用beautyfulsoup findall首先找到div。该表位于div中。我找不到该表。第二个问题是关于什么是穿越行的最佳方式。在这里举个例子,我想要csv格式的输出,应该用双引号括起来
例如:
“STANDALONE”、“Jun’16”、“Mar’16”,“Dec’15”、“Sep’15”
“净销售额”,“16339.70”,“15589.40”,”15065.00“,”14824.50“
“其他收入”、“50.10”、“46.30”、“153.30”和“1087.40”
“净利润”、“1427.50”、“1693.90”、”1709.10“、”2223.70“
我的代码:
来自urllib。请求导入urlopen
从bs4导入BeautifulSoup
html = urlopen("http://www.moneycontrol.com/india/stockpricequote/computers-software/tataconsultancyservices/TCS")
bsObj = BeautifulSoup(html, "html.parser")
link = bsObj.findAll("div", id="findet_1")
table1 = link.find('table').find_all('tr')
我知道我们可以使用get_text获取值,并使用for循环遍历行。但我找不到唯一的桌子:(