Ilias Kaleridis
Ilias Kaleridis

Reputation: 123

Python keyword same as xml tag

I am trying to do some web scraping and I came across this problem: I wanna take a tag that's called <name> but name is also a keyword in python so when I try to take that tag with the code below:

entries_map = []
for entry in entries:
    entry_title = entry.title.text
    entry_author = entry.name
    entries_map.append(entry_author)
    entries_map.append(entry_title)

print(entries_map)

I get this: ['entry', "Some title I scraped", 'entry', "Some title I scraped", ...]

So how can I take that tag?

Upvotes: 0

Views: 52

Answers (1)

Barmar
Barmar

Reputation: 781716

You can use the .find() method to search for a child element with a specific tag.

    entry_author = entry.find('name').text

Upvotes: 1

Related Questions