帮我用python写一个从https://rest.uniprot.org/uniprotkb/q58505.xml中爬取PDB和method、resolution、chains的爬虫
时间: 2023-03-28 12:04:01 浏览: 133
好的,我可以回答这个问题。以下是Python代码:
```python
import requests
from bs4 import BeautifulSoup
url = "https://rest.uniprot.org/uniprotkb/q58505.xml"
response = requests.get(url)
soup = BeautifulSoup(response.content, "xml")
for entry in soup.find_all("entry"):
for dbReference in entry.find_all("dbReference", {"type": "PDB"}):
pdb_id = dbReference.get("id")
for property_ in dbReference.find_all("property"):
if property_.get("type") == "method":
method = property_.get("value")
elif property_.get("type") == "resolution":
resolution = property_.get("value")
elif property_.get("type") == "chains":
chains = property_.get("value")
print(f"PDB ID: {pdb_id}, Method: {method}, Resolution: {resolution}, Chains: {chains}")
```
这个爬虫可以从指定的URL中获取PDB ID、方法、分辨率和链的信息,并将其打印出来。