开发者

LXml Xpath processing of multi-line field

I'm doing some scraping of a page and I'm fine with getting most fields, but having some problems with the开发者_StackOverflow中文版 address.

<address>
  56 South Ave
  <br>
  Miami, FL 33131
  <br>
</address>

address = myWebPage.xpath("//div[contains(@class,'rightcol')]//address")

I can get the first line, 56 South Avenue, using the above code. But I can't get the city, state, zip. How would I change the code to get the full address?


//div[contains(@class,'rightcol')]//address/text()[1]

selects the first text-node child of address:

"  
  56 South Ave   
  "

//div[contains(@class,'rightcol')]//address/text()[2]

selects the second text-node child of address:

"       
  Miami, FL 33131       
  "

//div[contains(@class,'rightcol')]//address/text()

selects both text-node children of address.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜