我一直试图搜索AlphaFold蛋白质结构数据库的搜索结果,但是在刮取结果中找不到想要的信息。所以我的想法是,如果我把搜索关键字“Alpha-elapitoxin Oh2b”放在搜索栏中,然后点击搜索按钮,它将生成一个新页面,其中的网址是:https://alphafold.ebi.ac.uk/search/text/Alpha-elapitoxin-Oh2b,在google中,我使用“检查”来检查这个页面的代码,并找到我想要的搜索结果,也就是这个蛋白质的if : P82662。但是,当我使用请求和bs4来抓取这个页面时。我在返回的信息中找不到想要的"P82662“,甚至连搜索词”Alpha-elapitoxin Oh2b“都找不到。
import requests
from bs4 import BeautifulSoup
response = requests.get('https://alphafold.ebi.ac.uk/search/text/Alpha-elapitoxin-Oh2b')
html = response.text
soup = BeautifulSoup(html, "html.parser")
print(soup.prettify())我搜索了StackOverflow,并试图找到一个无法通过BS4和请求找到结果的解决方案,发现有人说这是因为搜索结果的页面被JavaScript包装了。那这是真的吗?我该如何解决这个问题?
谢谢!
发布于 2022-11-12 05:16:24
所需的搜索数据以json格式作为get方法,通过API从外部源动态加载。所以bs4得到了空ResultSet。
import requests
res= requests.get('https://alphafold.ebi.ac.uk/api/search?q=%28text%3A%2aAlpha%5C-elapitoxin%5C-Oh2b%20OR%20text%3AAlpha%5C-elapitoxin%5C-Oh2b%2a%29&type=main&start=0&rows=20')
for item in res.json()['docs']:
id_num =item['uniprotAccession']
print(id_num)输出:
P82662
https://stackoverflow.com/questions/74410477
复制相似问题