python - XPath with Scrapy node begins with \n -


i'm using scrapy on html like:

<td nowrap="" valign="top" align="right">     <br>     text here.     <br>     other text here     <br> </td> 

td[1]/text()[1] gives me:

(empty line) text here. 

i've tried normalize-space, i.e. normalize-space(td[1]/text()[1]), works when test in firefox extension, not in scrapy. think scrapy getting tripped \n , skips on (or takes first line of node, nothing). i've tried "preceding" , "following" code, think might considered 1 element, dom says nodevalue = "\ntext here" thoughts?,

extract every text, desired 1 index. instance:

response.xpath("//table[@id='myid']/tr[1]/td[1]//text()")[1] 

demo scrapy shell:

$ scrapy shell http://www.trobar.org/troubadours/coms_de_peiteu/guilhen_de_peiteu_01.php in [1]: table = response.xpath("//table")[2] in [2]: td = "".join(table.xpath(".//td[1]//text()").extract()) in [3]: print(td)  companho, farai un vers qu'er covinen, et aura-i mais de foudatz no-y de sen, et er totz mesclatz d'amor e de joy e de joven.  e tenguatz lo per vilan qui no-l enten, o dins son cor voluntiers non l'apren: greu partir si fai d'amor qui la troba talen.  dos cavalhs ai ma sselha, ben e gen, bon son et adreg per armas e valen, e no-ls puesc amdos tener, que l'us l'autre non cossen.  si-ls pogues adomesjar mon talen, ja no volgr'alhors mudar mon garnimen, que meils for'encavalguatz de nuill ome viven.  launs fon dels montaniers lo plus corren, mas aitan fer' estranhez'a longuamen et es tan fers e salvatges, que del bailar si defen.  l'autre fon noyritz sa jus part cofolen ez anc no-n vis bellazor, mon escien: aquest non er ja camjatz ni per aur ni per argen.  qu'ie-l donei son senhor polin payssen, pero si-m retinc ieu tan de covenen que, s'ilh lo tenia un an, qu'ieu lo tengues mais de cen.  cavalier, datz mi cosselh d'un pessamen: -anc mays no fuy issaratz de cauzimen- : res non sai ab qual me tengua, de n'agnes o de n'arsen.  de gimel ai lo castel e-l mandamen, e per niol fauc ergueill tota gen: c'ambedui me son jurat e plevit per sagramen. 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -