这是一个用于获取物理师会议报告的简单爬虫,数据库表结构正在不断完善中

爬虫信息:

 # -*- coding:utf-8 -*-
import urllib.request
import pymysql
from bs4 import BeautifulSoup
import requests
import time
import re
import os # 数据库连接基础类
class Conn_Mssql:
#查询Mysql数据库
def Select_mssql(strsql):
#数据库连接信息
conn = pymysql.connect("DESKTOP-V9MQNL6", "root", "password", "internetdaq", charset="utf8")
cur = conn.cursor()
cur.execute(strsql)
return cur
#插入与更新数据库
def InsertOrUpdate_mssql(strsql):
# 数据库连接信息
conn = pymysql.connect("DESKTOP-V9MQNL6", "root", "password", "internetdaq", charset="utf8")
cur = conn.cursor()
cur.execute(strsql)
conn.commit()
conn.close()
return cur #获取网络信息中的信息,并存储
class Get_HttpMessage:
# 下载文件
def getFile(url):
try:
file_name = url.split('/')[-1]
file_path = "StorePDF\\"+file_name
u = urllib.request.urlopen(url)
except :
print(url, "url file not found")
return
block_sz = 90192
with open(file_path, 'wb') as f:
while True:
buffer = u.read(block_sz)
if buffer:
f.write(buffer)
else:
break
print("Sucessful to download" + " " + file_name)
#开始获取网络信息
def startGet():
print('start')
#链接的APPM网络
url = "https://www.aapm.org/pubs/reports/"
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
data = response.read()
soup = BeautifulSoup(data,"lxml")
#href属性包含docid字符串
for link in soup.find_all(href=re.compile("docid")):
#地址值
text_url = link['href']
#地址名称
text_Name = link.get_text()
if len(text_url)>0 and len(text_Name)>10 :
strSQl = "insert into daqtest (SAVE_TIME,URL_Name,URL_Link) values (NOW(),'" + text_Name + "','" +url+ text_url + "')"
strSQl =strSQl.encode('utf8')
try:
#存储地址信息
Conn_Mssql.InsertOrUpdate_mssql(strSQl)
except:
print('母页面MySQL存储失败')
            
time.sleep(1)
#含有论文的网页地址
urlSecond = url + text_url
request2 = urllib.request.Request(urlSecond)
response2 = urllib.request.urlopen(request2)
data2 = response2.read()
soup2 = BeautifulSoup(data2, "lxml")
#此变量用于消除重复的PDF信息
pdfName = ""
#查询网页中的PDF信息
for link2 in soup2.find_all(href=re.compile("pdf")):
#PDF信息
text_url2 = link2['href']
#PDF的所在网页来源
text_Name2 = url + text_url
if len(text_url2) > 0 and pdfName != text_url2:
pdfName = text_url2
strSQl2 = "insert into daqtest (SAVE_TIME,URL_Name,URL_Link) values (NOW(),'" + text_Name2 + "','" + text_url2 + "')"
strSQl2 = strSQl2.encode('utf8')
try:
#存储PDF信息至数据库
Conn_Mssql.InsertOrUpdate_mssql(strSQl2)
#慢一点,减缓网站压力
time.sleep(1)
#下载论文中的PDF文件
Get_HttpMessage.getFile(text_url2)
except:
print('子页面MySQL存储失败')
#程序入口
Get_HttpMessage.startGet()

这是用于存储的数据库表结构

 /*
Navicat MySQL Data Transfer Source Server : dde
Source Server Version : 50624
Source Host : DESKTOP-V9MQNL6:3306
Source Database : internetdaq Target Server Type : MYSQL
Target Server Version : 50624
File Encoding : 65001 */ SET FOREIGN_KEY_CHECKS=0; -- ----------------------------
-- Table structure for daqtest
-- ----------------------------
DROP TABLE IF EXISTS `daqtest`;
CREATE TABLE `daqtest` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`SAVE_TIME` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`URL_Name` varchar(600) COLLATE utf8_unicode_ci DEFAULT NULL,
`URL_Link` varchar(6000) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4634 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Python获取会议部分的信息内容(不断完善中)的更多相关文章

  1. Python 获取Facebook用户的Friends的爱好中的Top10

    CODE; #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...

  2. Python 获取Facebook用户Friends的爱好类别中的Top10

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...

  3. python获取系统内存占用信息的实例方法

    psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系统监控, ...

  4. 使用shell/python获取hostname/fqdn释疑

    一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...

  5. 使用 python 获取 httpd 程序所占用物理内存

    #!/usr/bin/env python #encoding: utf-8 ''' 思路: /proc/xx_pid/status 文件中的关键字段 VmRSS 来获取某个进程占用的物理内存 步骤: ...

  6. python 获取日期

    转载   原文:python 获取日期 作者:m4774411wang python 获取日期我们需要用到time模块,比如time.strftime方法 time.strftime('%Y-%m-% ...

  7. python获取字母在字母表对应位置的几种方法及性能对比较

    python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://project ...

  8. python获取文件大小

    python获取文件大小 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- import os # 字节bytes转化kb\m\g def formatSiz ...

  9. python 获取一个列表有多少连续列表

    python 获取一个列表有多少连续列表 例如 有列表 [1,2,3] 那么连续列表就是 [1,2],[2,3],[1,2,3] 程序实现如下: 运行结果:

随机推荐

  1. css中的背景色渐变以及背景图的定位

    单纯的背景色渐变: background: -webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #fff), color-stop(1, #ddd) ...

  2. swift textview禁止用户使用复制粘贴

    //自定义一个TextView class Own_TextView: UITextView { override func caretRect(for position: UITextPositio ...

  3. MyGod_alpha版本测试报告

    买尬-Alpha版本测试报告 @(二手市场APP)[MyGod团队|团队项目|版本测试] 项目名称:武汉大学校园二手市场APP--买尬 软件版本:1.0.0 开发团队:MyGod 开发代表:程环宇 张 ...

  4. Alpha冲刺Day4

    Alpha冲刺Day4 一:站立式会议 今日安排: 我们把项目大体分为四个模块:数据管理员.企业人员.第三方机构.政府人员.完成了数据库管理员模块.因企业人员与第三方人员模块存在大量的一致性,故我们团 ...

  5. java第5章学习总结

    学号20145336 <Java程序设计>第5周学习总结 教材学习内容总结 try catch JVM会先尝试执行try区块中的内容,若发生错误且与catch后面的类型相符,则执行catc ...

  6. cpp常用函数总结

    //sprintf sprintf(temp_str_result, "%lf", temp_double); result = temp_str_result; (*begin) ...

  7. Beta冲刺Day2

    项目进展 李明皇 今天解决的进度 优化了信息详情页的布局:日期显示,添加举报按钮等 优化了程序的数据传递逻辑 明天安排 程序运行逻辑的完善 林翔 今天解决的进度 实现微信端消息发布的插入数据库 明天安 ...

  8. Golang学习--平滑重启

    在上一篇博客介绍TOML配置的时候,讲到了通过信号通知重载配置.我们在这一篇中介绍下如何的平滑重启server. 与重载配置相同的是我们也需要通过信号来通知server重启,但关键在于平滑重启,如果只 ...

  9. EasyUI Datagrid 分页的情况下实现点击表头的小三角图标对数据库中所有数据重新排序

    说明一下: 当点击 datagrid 表头某一列的小三角图标时,easyui 本身是有排序的,但是在当我们对 datagrid 进行了分页的情况下,点击排序只是对当前页的数据进行排序,而需求需要我对数 ...

  10. Spring知识点回顾(06)Profile 和 条件注解 @Conditional

    1.设定环境中的active profiles 如:DispatcherServerlet的init-param spring.profiles.active=production spring.pr ...