import requests
import time
from lxml import etree
import pandas as pd
from sqlalchemy import create_engine
class KYLC():
def __init__(self):
self.url = 'https://www.kylc.com/stats/global/yearly/g_gdp/{}.html'
self.headers = {'设置你的headers'}
self.time = [i for i in range(1960,2020)]
"""抓取网页数据"""
def get_raw_data(self):
tables = pd.DataFrame()
# GDP表的编制是从1960年开始的
for i in self.time:
url = self.url.format(i)
time.sleep(1)
resp = requests.get(url, headers= self.headers).text
tree = etree.HTML(resp)
code_list = tre