Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7421243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:22:31+00:00 2026-05-29T08:22:31+00:00

I am parsing an XML feed from Google using beautifulstonesoup and python, and it

  • 0

I am parsing an XML feed from Google using beautifulstonesoup and python, and it works great. I am also creating a csv and uploading it to Google Docs, which works fine as well. The problem is when I come across an empty text attribute in the xml, the parser just stops. It is not a problem now, because all of the attributes have data, but the first time they don’t, it will break.

The code:

import atom
import gdata.auth
import gdata.contacts
import gdata.contacts.client
import gdata.docs.service
import gdata.docs.data
from BeautifulSoup import BeautifulStoneSoup as Soup
import csv

email = 'admin@domain.com'
password = 'password'
domain = 'domain.com'

ms_client = gdata.docs.service.DocsService()
gd_client = gdata.contacts.client.ContactsClient(domain=domain)
gd_client.ClientLogin(email, password, 'profileFeedAPI')
ms_client.ClientLogin(email, password, 'peopleCSVupload')

profiles_feed = gd_client.GetProfilesFeed('https://www.google.com/m8/feeds/profiles/domain/domain.com/full?max-results=300')

soup = Soup(str(profiles_feed), selfClosingTags=['ns0:category','ns3:status', 'ns0:link','ns1:email'])

a = soup.findAll('ns0:entry')
f = open('C:\\people.csv', 'wb')

writer = csv.writer(f, quoting=csv.QUOTE_NONE, escapechar =' ')

for entry in a:
    writer.writerow([entry.find('ns1:familyname').text + ',' + entry.find('ns1:givenname').text + ',' + entry.find('ns1:fullname').text + ',' + entry.find('ns1:orgtitle').text + ',' + entry.find('ns1:orgdepartment').text + ',' + entry.find('ns1:orgname').text + ',' + entry.find('ns1:email',primary=True)['address']])

f.close()

ms = gdata.data.MediaSource(file_path="C:\\people.csv", content_type=gdata.docs.service.SUPPORTED_FILETYPES['CSV'])
csv_entry = ms_client.Upload(ms, "People File")

I know I could do this:

for entry in a:
    if entry.find('ns1:orgtitle') != None:
        print entry.find('ns1:orgtitle').text
    elif entry.find('ns1:orgtitle') == None:
        print('')
    if entry.find('ns1:familyname') != None:
        print entry.find('ns1:familyname').text
    elif entry.find('ns1:familyname') == None:
        print('')
        etc...

But it is very long, and I don’t know how to concentrate the data to appear on one row. Any help, much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:22:32+00:00Added an answer on May 29, 2026 at 8:22 am

    you can wrap the find like this:

    def findnonempty(entry, arg):
        result = entry.find(arg):
        if result:
            return result.text
        else:
            return "" 
    

    the you can either do the 7 calls one after each other or you can use map(), like

    tags = ['ns1:familyname', 'ns1:givenname', ... ] # your tags
    s = map(lambda tag: findnonempty(entry, tag), tags)
    "".join(s)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am parsing some XML from an RSS feed (using NSXMLParser) for a blog
I'm parsing XML results from an API call using PHP and xpath. $dom =
I'm using JAXB to generate XML that is uploaded to our Google feed. While
I am parsing an RSS feed from the following URL: http://rss.sciam.com/ScientificAmerican-Global?format=xml // $xml_text is
I m reading the xml images from rss feed and parsing it in UITable
I am parsing text/html from web pages into an xml feed, the text/html is
I am parsing XML with an XMLReader using a XMLReaderSettings object with the event
Following on from my recent question regarding parsing XML files in Java I have
I am looking to create an expression tree by parsing xml using C#. The
this is my first time using StAX for parsing XML documents (still in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.