Click here to Skip to main content
14,206,970 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I need to get empty values too from xml query which returns the links as the resultant array.There are some degrees which doesn't have links to refer.When printing, the corresponding empty results are not getting printed.

The objective is getting the links of corresponding degrees.

My code is:

postgraduatedegrees=tree.xpath('//*[@id="block-scholarly- 
      content"]/div/article/div/div/div//*[contains(text(),"Degree 
      of")]/text()')

      postgraduatedegreeslinks=tree.xpath('//*[@id="block-scholarly- 
      content"]/div/article/div/div/div//*[contains(text(),"Degree of")]/@href')

      Output:
       len(postgraduatedegrees)
       Out[222]: 52

      len(postgraduatedegreeslinks)
       Out[223]: 40

The empty values are getting removed.
Please help me to solve the issue

What I have tried:

I have tried using string(.) and textContant()

postgraduatedegreeslinks=tree.xpath('//*[@id="block-scholarly- 
      content"]/div/article/div/div/div//*[contains(text(),"Degree of")][@href]/text()')

for p in postgraduatedegreeslinks
      print (p.extract)


Not worked for me.
Posted
Updated 3-Sep-18 2:04am
v2
Comments
Richard MacCutchan 3-Sep-18 8:12am
   
"Not worked for me."
And we are expected to divine your mind to discover what that could mean?
Gowshalini Rajalingam 3-Sep-18 8:39am
   
I have tried.But didn't get the problem solved.can any one please help me? if the question is not clear, please clarify with me.I'm glad to explain.
Eric Lynch 3-Sep-18 14:26pm
   
The problem is that you're not providing enough information for people to understand your question and help. Try improving your question to include information like:

1) your input XML
2) your expected output
3) your actual output
4) a brief description of how your expected output differs from your actual output

As your question currently stands, we understand that its "not working", but we have no idea about what (exactly) fails to meet your expectations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190612.1 | Last Updated 3 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100