【发布时间】:2018-05-22 05:00:37
【问题描述】:
我正在尝试访问此网页上的序列:
https://www.ncbi.nlm.nih.gov/protein/EGW15053.1?report=fasta
序列存储在 div class="seq gbff" 下。每一行都存放在
下<span class='ff_line' id='gi_344258949_1"> *line 1 of sequence* </span>
当我尝试搜索包含该序列的 span 时,beautiful soup 返回 None。当我尝试查看spans 上方的div 的子项或内容时,同样的问题。
代码如下:
import requests
import re
from bs4 import BeautifulSoup
# Create a variable with the url
url = 'https://www.ncbi.nlm.nih.gov/protein/EGW15053.1?report=fasta'
# Use requests to get the contents
r = requests.get(url)
# Get the text of the contents
html_content = r.text
# Convert the html content into a beautiful soup object
soup = BeautifulSoup(html_content, 'html.parser')
div = soup.find_all('div', attrs={'class', 'seq gbff'})
for each in div.children:
print(each)
soup.find_all('span', aatrs={'class', 'ff_line'})
这两种方法都不起作用,我将非常感谢任何帮助:D
【问题讨论】:
标签: python beautifulsoup