###webページにアクセスして、XML解析をしたい
以下のようなXMLで書かれたWebページがあります。
xml
1<outgoingServer type="smtp"> 2<hostname>smtp.gmail.com</hostname> 3<port>465</port> 4<socketType>SSL</socketType> 5<username>%EMAILADDRESS%</username> 6<authentication>OAuth2</authentication> 7<authentication>password-cleartext</authentication> 8</outgoingServer>
<outgoingServer>タグで囲まれた部分の内容を取得したいです。
以下のコードを書きましたが、思うような結果が得られませんでした。
python
1from urllib.request import urlopen 2from bs4 import BeautifulSoup 3 4if __name__ == "__main__": 5 req = urlopen('https://autoconfig.thunderbird.net/v1.1/gmail.com') 6 html = req.read() 7 soup = BeautifulSoup(html, "lxml") 8 ans = soup.find('outgoingServer', {'type':'smtp'}) 9 print(ans)
###得られた結果
python
1None
###欲しかった結果
python
1<hostname>smtp.gmail.com</hostname> 2<port>465</port> 3<socketType>SSL</socketType> 4<username>%EMAILADDRESS%</username> 5<authentication>OAuth2</authentication> 6<authentication>password-cleartext</authentication>
なにがいけないのでしょうか?
よろしくお願いします。
###環境
anaconda3
python3.4を使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。