I am trying to capture data from two nodes that have the same name. I am using the find method but it always pulls the value that is nested as opposed to the first child node. I've tried a few different methods to target but I am not having any success. Any help is appreciated as always.
API Response:
<affiliate_export_response>
<success>true</success>
<row_count>1</row_count>
<affiliates>
<blacklists>
<blacklist>
<advertiser>
<advertiser_id xmlns="API:id_name_store">2</advertiser_id>
<advertiser_name xmlns="API:id_name_store">wayne's Ad</advertiser_name>
</advertiser>
<affiliate>
<affiliate_id xmlns="API:id_name_store">3</affiliate_id>
<affiliate_name xmlns="API:id_name_store">Mark Affiliate</affiliate_name>
</affiliate>
<blacklist_reason>
<blacklist_reason_id xmlns="API:id_name_store">1</blacklist_reason_id>
<blacklist_reason_name xmlns="API:id_name_store">404</blacklist_reason_name>
</blacklist_reason>
<blacklist_type>
<blacklist_type_id xmlns="API:id_name_store">3</blacklist_type_id>
<blacklist_type_name xmlns="API:id_name_store">404</blacklist_type_name>
</blacklist_type>
<date_created>2018-04-26T00:00:00</date_created>
</blacklist>
</blacklists>
<date_created>2018-01-29T11:40:58.34</date_created>
<notes />
</affiliate>
</affiliates>
</affiliate_export_response>
Code:
import requests
from bs4 import BeautifulSoup
url = 'API URL'
params = {
'param1':'dfasdf',
'param2':3
}
r = requests.get(url, params=params)
soup = BeautifulSoup(r.text, 'lxml')
for affiliate in soup.select('affiliate'):
date_created = affiliate.find('date_created').string
print(date_created)
The goal is to capture 2018-01-29T11:40:58.34 but I am capturing the nested date_created node inside blacklists and getting 2018-04-26T00:00:00 instead.