import json
import requests
import re
class Kr36(object):
def __init__(self):
# 利用首页
self.url = 'https://36kr.com/'
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
}
# ajax发送请求下一页
self.ajax_url='https://36kr.com/api/search-column/mainsite?per_page=20&page={}'
self.file = open('kr36.json','w')
self.page = 1
def get_data(self,url):
resp = requests.get(url,headers=self.headers)
print(resp)
return resp.content.decode()
# 解析数据
def parse_data(self,data):
# 利用正则从标签中提取需要的数据
result = re.findall('<script>var props=(.*?)</