我想提取m:properties
标记之间的数据值。我怎么能这样做?
<entry>
<id>http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(7086)</id>
<title type="text"></title>
<updated>2018-04-25T02:39:22Z</updated>
<author>
<name />
</author>
<link rel="edit" title="DailyTreasuryYieldCurveRateDatum" href="DailyTreasuryYieldCurveRateData(7086)" />
<category term="TreasuryDataWarehouseModel.DailyTreasuryYieldCurveRateDatum" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">7086</d:Id>
<d:NEW_DATE m:type="Edm.DateTime">2018-04-24T00:00:00</d:NEW_DATE>
<d:BC_1MONTH m:type="Edm.Double">1.7</d:BC_1MONTH>
<d:BC_3MONTH m:type="Edm.Double">1.87</d:BC_3MONTH>
<d:BC_6MONTH m:type="Edm.Double">2.05</d:BC_6MONTH>
<d:BC_1YEAR m:type="Edm.Double">2.25</d:BC_1YEAR>
<d:BC_2YEAR m:type="Edm.Double">2.48</d:BC_2YEAR>
<d:BC_3YEAR m:type="Edm.Double">2.63</d:BC_3YEAR>
<d:BC_5YEAR m:type="Edm.Double">2.83</d:BC_5YEAR>
<d:BC_7YEAR m:type="Edm.Double">2.95</d:BC_7YEAR>
<d:BC_10YEAR m:type="Edm.Double">3</d:BC_10YEAR>
<d:BC_20YEAR m:type="Edm.Double">3.08</d:BC_20YEAR>
<d:BC_30YEAR m:type="Edm.Double">3.18</d:BC_30YEAR>
<d:BC_30YEARDISPLAY m:type="Edm.Double">3.18</d:BC_30YEARDISPLAY>
</m:properties>
</content>
我尝试使用请求
r = requests.get('http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData?$filter=month(NEW_DATE)%20eq%204%20and%20year(NEW_DATE)%20eq%202018')
soup = BeautifulSoup(r.text, 'lxml')
data = soup.find(id ='http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(7086)')
print(data)
输出为None
答案 0 :(得分:1)
import requests
from bs4 import BeautifulSoup
r = requests.get('http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData?$filter=month(NEW_DATE)%20eq%204%20and%20year(NEW_DATE)%20eq%202018')
soup = BeautifulSoup(r.text, 'lxml')
data = soup.find_all("content")
for i in data:
print(i)