I am new to web scraping. I would like to collect the data from:
https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11
I can see a lot of TOCs are there. I would like to scrape the "Income before income taxes"
word with the amount. Please share idea and throw some lights on this.
JavaScript
x
7
1
base_url="https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11"
2
from lxml.etree import fromstring, HTMLParser
3
import requests
4
r = requests.get(base_url).content
5
xml = fromstring(r, HTMLParser())
6
print(xml.xpath("//span[@class='Text Intro Justify' and contains(text(),'impact')]//text()"))
7
Advertisement
Answer
This will give your all the things from the table, you can just find the specific you want:
JavaScript
1
12
12
1
import urllib2
2
from bs4 import BeautifulSoup
3
quote_page = 'https://www.sec.gov/Archives/edgar/data/814453/000119312518067603/d494599d10k.htm#tx494599_11'
4
page = urllib2.urlopen(quote_page)
5
soup = BeautifulSoup(page, 'html.parser')
6
7
header = soup.find("b", text="2017 (1)")
8
table = header.find_parent("table")
9
10
for row in table.find_all("tr")[2:]:
11
print([cell.get_text(strip=True) for cell in row.find_all("td")])
12