You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
995 B
34 lines
995 B
import requests
|
|
import json
|
|
from bs4 import BeautifulSoup
|
|
import re
|
|
import time
|
|
|
|
|
|
class InNews:
|
|
def __init__(self):
|
|
self.eventDescription=''
|
|
self.eventTime=''
|
|
self.eventUrl=''
|
|
self.siteName=''
|
|
self.Artical=''
|
|
|
|
def printArtical(self):
|
|
req = requests.get(self.eventUrl)
|
|
content = req.content.decode('utf-8')
|
|
contentBs = BeautifulSoup(content, 'html.parser')
|
|
tag = contentBs.findAll('span', attrs={'class': 'bjh-p'})
|
|
artical = ''
|
|
for item in tag:
|
|
artical=artical+(' '+item.get_text())+'\n'
|
|
return artical
|
|
|
|
def time(self):
|
|
ts = float(self.eventTime)
|
|
localt = time.localtime(ts) # 转换为localtime对象
|
|
timestr = time.strftime("%Y-%m-%d %H:%M:%S", localt) # 格式化
|
|
return(timestr)
|
|
|
|
def toString(self):
|
|
print('%s\n原网:%s\n%s\n\n%s\n%s'%(self.eventDescription,self.eventUrl,self.time(),self.printArtical(),self.siteName))
|