使用python获取历史上的今天发生了什么事?
发布时间
阅读量:
阅读量
使用python获取历史上的今天
-
前言
-
代码
-
- 引入库
- 部分代码
-
最后
前言
数据来源
self.domain = [‘www.lssdjt.com’]
self.base_url = ‘http://www.lssdjt.com’
代码
引入库
import requests, json, re, os, sys, datetime,time
import traceback
import historySqlite
from urllib.parse import urlparse
from contextlib import closing
from urllib.request import urlopen
from bs4 import BeautifulSoup
代码解释
部分代码
def __init__(self):
self.headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
}
self.domain = ['www.lssdjt.com']
self.base_url = 'http://www.lssdjt.com'
def run(self):
for m in range(12,13):
for d in range(1,32):
url = self.base_url + '/'+ str(m)+'/'+str(d)
response = requests.get(url, headers=self.headers)
if not response.status_code == 200:
print('请求失败,地址有误'+url)
continue
print('请求地址:' + url)
response.encoding = 'utf-8'
self.html = response.text
soup = BeautifulSoup(self.html,'html.parser')
events = soup.select('.main ul .gong')
代码解释
最后
完整代码这里下载:去看看
全部评论 (0)
还没有任何评论哟~
