ScrapyフレームワークのCSSセレクタを使用してHTMLの要素を選択/一致させようとしています。しかし、最後の子セレクタで抽出したいフィールドの1つにぶつかりました。scrapy CSS最後の子セレクタがテキストの選択に失敗する
<td class="Table-Standard-AwardName Table-Scholarship-AwardName">
<a id="ctl00_ContentPlaceHolder1_ScholarshipDataControl_grvScholarshipSearch_ctl02_hylScholarshipName" class="bold" href="/Scholarships/14123/Family-Bursary,-The">Family Bursary, The</a>
<br>
<span>Field of Study:</span>
EcologyEnvironmental Science
</td>
テキスト "EcologyEnvironmental科学は" 私が一致していることである。ここでは
はHTMLです。
私は最後の子は出力が示す「研究分野」をセレクタ使用:
In [3]: response.css('td.Table-Standard-AwardName.Table-Scholarship-AwardName > *:last-child::text').extract_first()
Out[3]: 'Field of Study:'
私は他の質問を通して見て、無駄に、nth-last-child() and combined sibling
セレクタのような複数の方法を試してみました。助けて!
は 'response.cssをお試しください( 'td.Table-Standard-AwardName.Tabl e-Scholarship-AwardName> * :: text ')[ - 1] .extract() 'となります。 –
xpathを使用しますか? – Jasonw
それと、インスペクタが与えた 'response.xpath( '// * [@ id =" ctl00_ContentPlaceHolder1_ScholarshipDataControl_grvScholarshipSearch "]/tbody/tr [2]/td [2]/text() ') 'となります。どちらも出力をもたらさなかった。 –