text: import requests
  from requests.exceptions import RequestException
  import re
  import json
  from bs4 import BeautifulSoup   #都是基本的几个库
  import urllib3 
  def get_one_page(url):
      try:
          response=requests.get(url)
          if response.status_code == 200:
              return response.text
          return None
      except RequestException:
          return None
  
  def get_the_floor_time(html):   
      http=urllib3.PoolManager()
      response=http.request('GET',html)
      soup = BeautifulSoup(response.data.decode('utf-8'),'features="lxml"')
      items=soup.find_all('span',{'class':'sumpage'})  
      pattern = re.compile('<span class="sumpage">(\d.*?)</span>', re.S)   
      items = re.findall(pattern, str(items))
      return items  
  
  def get_the_content(html):   
      http=urllib3.PoolManager()
      response=http.request('GET',html)
      soup = BeautifulSoup(response.data.decode('utf-8'),'features="lxml"')
      contents=soup.find_all('span',{'class':'sub'})
      if contents:
          items=get_the_floor_time(html)
          i=-1
          for content in contents:
              content=content.get_text().strip()   
              i=i+1
              print(items[2 * i])
              write_to_file(items[2 * i])   #写入数据
              print(items[2 * i + 1])
              write_to_file(items[2 * i + 1])
              print(content)
              write_to_file(content)
              print('------------------------------------------------')
              write_to_file('--------------------------------------')
      else:
          print("获取帖子内容失败")
  
  def write_to_file(content):   #这基本是标配了
      with open('bdtb_result.text','a',encoding='utf-8') as f:
          f.write(json.dumps(content,ensure_ascii=False)+'\n')
          f.close()
  
  def main():
      a=get_the_floor_time('https://guba.eastmoney.com/jj_1.html')
      for i in a:
          url = 'http://guba.eastmoney.com/jj_'+str(i)+'.html'
          get_one_page(url)
          html=get_one_page(url)
          get_the_content(html)
          
  if __name__=='__main__':
          main()