开发者

LXml Xpath processing of multi-line field

开发者 https://www.devze.com 2023-01-11 13:32 出处:网络
I\'m doing some scraping of a page and I\'m fine with getting most fields, but having some problems with the开发者_StackOverflow中文版 address.

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

精彩评论

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