Reputation: 115
I have gotten a code and after working out the indentation problem in it, it runs without errors, however now I cannot print the code into a list.
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
import requests
symbol = 'AAPL'
url = "https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=" + symbol + "&type=&dateb=&owner=exclude&start=0&count=100&output=atom"
uClient = uReq(url)
page_html = uClient.read()
uClient.close()
html = soup(page_html, 'html.parser')
entries = html.findAll("entry")
shouldContinue = True
link = ""
for entry in entries:
if shouldContinue and (
entry.find("category")["term"].lower() == "10-k" or entry.find("category")["term"].lower() == "10-q" or
entry.find("category")["term"].lower() == "20-f"):
firstUrl = entry.find("link")["href"]
uClientFirstUrl = uReq(firstUrl)
page_html_firstUrl = uClientFirstUrl.read()
uClientFirstUrl.close()
htmlFirstUrl = soup(page_html_firstUrl, 'html.parser')
tds = htmlFirstUrl.findAll("table")[1].findAll("td")
foundtd = False
for td in tds:
if foundtd == True:
link = "https://www.sec.gov" + td.find("a")["href"]
foundtd = False
if "xbrl instance" in td.text.lower():
foundtd = True
shouldContinue = False
def getCash(url, symbol):
uClient = uReq(url)
page_html = uClient.read()
uClient.close()
xml = soup(page_html, 'xml')
cash = xml.findAll("us-gaap:CashAndCashEquivalentsAtCarryingValue")
if len(cash) == 0:
cash = xml.findAll("ifrs-full:Cash")
if len(cash) == 0:
cash = xml.findAll("us-gaap:CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents")
if len(cash) == 0:
cash = xml.findAll("us-gaap:Cash")
return cash
print(getCash)
getCash(url, symbol)
I have tried printing the assignment, as well as calling the method without any success. A sense of direction would be appreciated. Thank you.
Upvotes: 0
Views: 71
Reputation: 9711
As mentioned in my comment above:
What effect do you expect from print(getCash)
? If you want it to print the return from the getCash()
function, delete it (it's not doing anything), and wrap your getCash(url, symbol)
call in a print()
function.
Basically, do this:
print(getCash(url, symbol))
Upvotes: 1