个人作业2-6.4-Python爬取顶会信息
1、个人作业2
数据爬取阶段
import requests
from lxml import etree
import pymysql
def getdata(url):
# 请求CVPR主页
page_text = requests.get(url).text
parser = etree.HTMLParser(encoding="utf-8")
tree = etree.HTML(page_text, parser=parser)
#html
# 爬取论文连接
hrefs = tree.xpath('//dt[@class="ptitle"]/a/@href')
print(len(hrefs))
# 爬取论文信息
titles = []
pdfs = []
abstracts = []
authors = []
keywords = []
for href in hrefs:
db = pymysql.connect(host="127.0.0.1", user="root", password="lin0613",
database="users")
href = "https://openaccess.thecvf.com/" + href
page_text = requests.get(href).text
tree_link = etree.HTML(page_text, parser=parser)
title = tree_link.xpath('/html/body/div/dl/dd/div[@id="papertitle"]/text()')
title[0] = title[0].strip()
titles += title
title[0] = title[0].replace(":", "")
words = title[0].split()
keyword = ""
for word in words:
if checkword(word):
save_keywords(pymysql.connect(host="127.0.0.1", user="root", password="lin0613",database="users"), word)
keyword += word + " "
keywords.append(keyword)
pdf = tree_link.xpath('/html/body/div/dl/dd/a[contains(text(),"pdf")]/@href')
pdf[0] = pdf[0].replace("../../", "https://openaccess.thecvf.com/")
pdfs += pdf
abstract = tree_link.xpath('/html/body/div/dl/dd/div[@id="abstract"]/text()')
abstract[0] = abstract[0].strip()
abstracts += abstract
author = tree_link.xpath('/html/body/div/dl/dd/div/b/i/text()')
authors += author
# print(title)
# print(author)
# print(pdf)
# print(abstract)
save(db, title[0], author[0], abstract[0], href, keyword)
print(titles)
print(hrefs)
print(authors)
print(abstracts)
print(pdfs)
def save(db, title, author, abstract, link, keyword):
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# SQL 插入语句
sql = "INSERT INTO papers(title, authors, abstract_text, original_link, keywords) \
VALUES ('%s', '%s', '%s', '%s', '%s')" % \
(title, author, abstract, link, keyword)
try:
# 执行sql语句
cursor.execute(sql)
print("true")
# 执行sql语句
db.commit()
except:
print("error wenzhang")
# 发生错误时回滚
db.rollback()
# 关闭数据库连接
db.close()
def save_keywords(db, keyword):
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# SQL 插入语句
sql = "INSERT INTO keywords(keyword) VALUES ('%s')" % (keyword)
try:
# 执行sql语句
cursor.execute(sql)
# 执行sql语句
print("true")
db.commit()
except:
print("error word")
# 发生错误时回滚
db.rollback()
# 关闭数据库连接
db.close()
def checkword(word):
invalid_words = ['the', 'a', 'an', 'and', 'by', 'of', 'in', 'on', 'is', 'to', "as", "from", "for", "with", "that",
"have", "by", "on", "upon", "about", "above", "across", "among", "ahead", "after", "a",
"analthough", "at", "also", "along", "around", "always", "away", "anyup", "under", "untilbefore",
"between", "beyond", "behind", "because", "what", "when", "would", "could", "who", "whom", "whose",
"which", "where", "why", "without", "whether", "down", "during", "despite", "over", "off", "only",
"other", "out", "than", "the", "thenthrough", "throughout", "that", "these", "this", "those",
"there", "therefore", "some", "such", "since", "so", "can", "many", "much", "more", "may", "might",
"must", "ever", "even", "every", "each" ,"with","A","With","From"]
if word.lower() in invalid_words:
return False
else:
return True
if __name__ == '__main__':
#getdata("https://openaccess.thecvf.com/CVPR2018?day=2018-06-20")
getdata("https://openaccess.thecvf.com/CVPR2018?day=2018-06-21")
getdata("https://openaccess.thecvf.com/CVPR2019?day=2019-06-18")
#getdata("https://openaccess.thecvf.com/CVPR2019?day=2019-06-19")
#getdata("https://openaccess.thecvf.com/CVPR2019?day=2019-06-20")
getdata("https://openaccess.thecvf.com/CVPR2020?day=2020-06-16")
#getdata("https://openaccess.thecvf.com/CVPR2020?day=2020-06-17")
#getdata("https://openaccess.thecvf.com/CVPR2020?day=2020-06-18")
#getdata("https://openaccess.thecvf.com/CVPR2018?day=2018-06-19")
个人作业2-6.4-Python爬取顶会信息的更多相关文章
- Python爬取拉勾网招聘信息并写入Excel
这个是我想爬取的链接:http://www.lagou.com/zhaopin/Python/?labelWords=label 页面显示如下: 在Chrome浏览器中审查元素,找到对应的链接: 然后 ...
- python爬取豆瓣视频信息代码
目录 一:代码 二:结果如下(部分例子) 这里是爬取豆瓣视频信息,用pyquery库(jquery的python库). 一:代码 from urllib.request import quote ...
- Python 爬取美团酒店信息
事由:近期和朋友聊天,聊到黄山酒店事情,需要了解一下黄山的酒店情况,然后就想着用python 爬一些数据出来,做个参考 主要思路:通过查找,基本思路清晰,目标明确,仅仅爬取美团莫一地区的酒店信息,不过 ...
- python 爬取豆瓣书籍信息
继爬取 猫眼电影TOP100榜单 之后,再来爬一下豆瓣的书籍信息(主要是书的信息,评分及占比,评论并未爬取).原创,转载请联系我. 需求:爬取豆瓣某类型标签下的所有书籍的详细信息及评分 语言:pyth ...
- python爬取电影网站信息
一.爬取前提1)本地安装了mysql数据库 5.6版本2)安装了Python 2.7 二.爬取内容 电影名称.电影简介.电影图片.电影下载链接 三.爬取逻辑1)进入电影网列表页, 针对列表的html内 ...
- python爬取豆瓣电影信息数据
题外话+ 大家好啊,最近自己在做一个属于自己的博客网站(准备辞职回家养老了,明年再战)在家里 琐事也很多, 加上自己 一回到家就懒了(主要是家里冷啊! 广东十几度,老家几度,躲在被窝瑟瑟发抖,) 由于 ...
- python爬取梦幻西游召唤兽资质信息(不包含变异)
一.分析 1.爬取网站:https://xyq.163.com/chongwu/ 2.获取网页源码: request.get("https://xyq.163.com/chongwu/&qu ...
- python 爬取bilibili 视频信息
抓包时发现子菜单请求数据时一般需要rid,但的确存在一些如游戏->游戏赛事不使用rid,对于这种未进行处理,此外rid一般在主菜单的响应中,但有的如番剧这种,rid在子菜单的url中,此外返回的 ...
- python爬取网业信息案例
需求:爬取网站上的公司信息 代码如下: import json import os import shutil import requests import re import time reques ...
随机推荐
- CF1514A Perfectly Imperfect Array 题解
Content 给定一个长度为 \(n\) 的序列,问是否存在一个非空子序列,使得这个子序列所有元素的积不是完全平方数. 数据范围:\(t\) 组数据,\(1\leqslant t\leqslant ...
- LuoguP7426 [THUPC2017] 体育成绩统计 题解
Update \(\texttt{2021.3.11}\) 修复了一个笔误. Content 太长了,请直接跳转回题面查看. 数据范围:\(n\leqslant 10^4\),\(0\leqslant ...
- AcWing822. 走方格
题目 给定一个\(n×m\)的方格阵,沿着方格的边线走,从左上角\((0,0)\)开始,每次只能往右或者往下走一个单位距离,问走到右下角\((n,m)\)一共有多少种不同的走法. 输入格式 共一行,包 ...
- docker启动报错:Failed to Setup IP tables: Unable to enable SKIP DNAT rule
Creating network "kafka_default" with the default driverERROR: Failed to Setup IP tables: ...
- 【LeetCode】345. Reverse Vowels of a String 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用栈 双指针 日期 [LeetCode] 题目地址 ...
- 【LeetCode】687. Longest Univalue Path 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetco ...
- 快速恢复update了的orcale数据表
在update的时候 没有写条件 将整个表中的数据全部都更新了,这时候怎么办呢? orcale提供了以下的方法产看某一个时间戳, 所执行的sql的语句内容, 同时可以利用该这个时间戳查看当时语句执行显 ...
- 面渣逆袭:JVM经典五十问,这下面试稳了!
大家好,我是老三,"面渣逆袭"系列继续,这节我们来搞定JVM.说真的,JVM调优什么的一个程序员可能整个职业生涯都碰不到两次,但是,一旦用到的时候,那就是救命了,而且最重要的是-- ...
- 精通 MySQL 索引
索引概念: 概念:索引是提高mysql查询效率的数据结构.总的一句话概括就是索引是一种提高查询效率的数据结构. 数据库查询是数据库的最主要功能之一.设计者们都希望查询数据的速度能尽可能的快,因此数据库 ...
- Unity3D开发入门教程(二)—— Lua入门
五邑隐侠,本名关健昌,12年游戏生涯. 本教程以 Unity 3D + VS Code + C# + tolua 为例. 如果你还没有编程基础,建议你先学习一些编程基础.本文不是完全菜鸟教程,主要针对 ...