我是网络剪贴的新手。我想从以下位置收集数据:
https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11
我可以看到很多 TOC 。我想用这个金额来刮掉"Income before income taxes"
这个词。请分享想法并对此加以说明。
base_url="https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11"
from lxml.etree import fromstring, HTMLParser
import requests
r = requests.get(base_url).content
xml = fromstring(r, HTMLParser())
print(xml.xpath("//span[@class='Text Intro Justify' and contains(text(),'impact')]//text()"))
答案 0 :(得分:0)
这将提供表格中的所有内容,您只需找到所需的特定内容即可
import urllib2
from bs4 import BeautifulSoup
quote_page = 'https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11'
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
header = soup.find("b", text="2017 (1)")
table = header.find_parent("table")
for row in table.find_all("tr")[2:]:
print([cell.get_text(strip=True) for cell in row.find_all("td")])