Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900