发布于 2019-06-10 11:46:58
有很多方法可以做到这一点。BeautifulSoup
并且requests
会让你的生活更轻松。我相信有更优化的解决方案,但有一个简单的解决方案可以演示如何实现这一目标。
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
res = requests.get('https://www.sec.gov/Archives/edgar/data/4904/000000490412000013/ye11aep10k.htm')
soup = BeautifulSoup(res.text)
wanted_pages = ['25', '37']
page_divs = [div for div in soup.find_all('div', id='PN')
if div.font.text in wanted_pages]
wanted_page_indices = [str(soup).find(str(div)) for div in page_divs]
section_str = str(soup)[slice(*wanted_page_indices)]
section_html = BeautifulSoup(section_str).prettify()
# do something with the section
您可以通过安装第三方库pip
。您可以将这样的内容粘贴到for
循环中,并按照我的理解为每个html页面执行此操作。希望我的问题是正确的,希望这有用。
https://stackoverflow.com/questions/-100006959
复制相似问题