如何使用scrapy从python中列出的td标签中列出日期?

时间:2017-10-12 06:32:55

标签: python-2.7 scrapy

<div class="fullwidth singleCalender"><table border="0" cellpadding="4" 
 cellspacing="0">

<tbody>
<tr style="display: table-row;">
<th colspan="7" style="text-align: right; font-weight: normal; padding: 0px 
8px;">Oct&nbsp;2018</th>

</tr>

<tr style="display: table-row;">
<td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
<td>Su</td>
</tr>

<tr style="display: none;">
<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td>
</tr>

<tr style="display: table-row;">
<td>8</td>
<td>9</td>
<td>
<a title="Start of event" style="text-decoration: 
none; background-color: rgb(144, 155, 31); color: rgb(255, 255, 255); font-
size: 14px; border-radius: 1px; padding: 0px 5px;">10</a>
</td>
<td>
<a title="Start of event" style="text-decoration: none; background-
color: rgb(144, 155, 31); color: rgb(255, 255, 255); font-size: 14px; 
border-radius: 1px; padding: 0px 5px;">11</a>
</td>
<td>
<a title="Start of event" 
style="text-decoration: none; background-color: rgb(144, 155, 31); color: 
rgb(255, 255, 255); font-size: 14px; border-radius: 1px; padding: 0px 
5px;">12</a>
</td>
<td><a title="Start of event" style="text-decoration: none; 
background-color: rgb(144, 155, 31); color: rgb(255, 255, 255); font-size: 
14px; border-radius: 1px; padding: 0px 5px;">13</a>
</td><td>14</td>
</tr>


<tr style="display: none;">
<td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td>
<td>21</td>
</tr>

<tr style="display: none;">
<td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td>
<td>28</td>
</tr>

<tr style="display: none;">
<td>29</td><td>30</td><td>31</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;
</td><td>&nbsp;</td>
</tr>

</tbody>
</table>
</div>

如何在td中获得标签=“事件开始”的10,11,12,13值。从使用scrapy的python中的代码?有人可以帮忙吗? Thanx提前..!我尝试使用此代码“response.css('div.fullwidth table tbody tr:nth-​​child(4)td a.Start :: text')。extract()” 但是我得到像这样的“[]”。

1 个答案:

答案 0 :(得分:0)

试试这个:

response.xpath('//a[contains(@title, "Start of event")]/text()').extract()