想我也包含XML輸出如下字符串:在使用Python BeautifulSoup下劃線更換所有的連字符在XML標籤
<dept-details>
<dept-domain-id>1</dept-domain-id>
<dept-req-status>no-vacancies-present</dept-req-status>
.
.
</dept-details>
我想替換包含連字符的所有標籤( - )與下劃線(_),因爲我發現Beautiful Soup不允許你直接訪問標籤,除了使用find()外,this的帖子和this都是這樣。
所以我的目的是要包含標籤轉換 - _使帶子的樣子:
<dept_details>
<dept_domain_id>1</dept_domain_id>
<dept_req_status>no-vacancies-present</dept_req_status>
.
.
</dept_details>
我想知道我怎麼可以使用Python重的方法來做到這一點,或者如果我能做到這一點與BeautifulSoup直接,這將是偉大的!
在此先感謝
BeautifulSoup非常適合HTML,對XML不太好。 –
[etree](http://docs.python.org/2/library/xml.etree.elementtree.html)更適合xml解析。 –