当我尝试运行我的代码时,我遇到了一个错误,即我错过了1个必需的位置参数:'self'。我不知道如何解决这个问题。
import urllib.request
import re
from lxml import html
class test:
def start(self) :
url = 'http://money.cnn.com/data/dow30/'
global Ticker
increase = 0
while increase < 30:
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
respData = resp.read()
html_data = html.fromstring(respData)
Ticker = html_data.xpath('//a[@class="wsod_symbol"]/text()')[increase]
print(Ticker)
return Ticker
increase += 1
start()
def earnings(self):
url = 'https://www.google.com/finance?q=NYSE:' + Ticker
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
respData = resp.read()
html_data = html.fromstring(respData)
eps = html_data.xpath('//td[@class="val"]/text()')[7]
blah = re.findall(r'\d+\.\d+', eps)
print(float(blah[0]))