爬取我爱竞赛网的大量数据

首先获取每一种比赛信息的分类链接

def get_type_url(url):
   web_data = requests.get(web_url)
   soup = BeautifulSoup(web_data.text, 'lxml')
   types = soup.select("#mn_P1_menu li a")
   for type in types:
       print(type.get_text())
       get_num(type.get("href"))

然后获取每一个分类连接中的总页数

def get_num(url):
   web_data = requests.get(url)
   soup = BeautifulSoup(web_data.text, 'lxml')
   num = soup.select(".pg span")
   # 部分页面没有分页只有一页,需要分类一下
   if(num!=[]):
       i = int(num[0].get_text().split(" ")[2])
       for w in range(1, i):
           print("第"+str(w)+"页")
           urls = url + "index.php?page={}".format(str(w))
           get_message_url(urls)
   else:
       get_message_url(url)

最后获取每一页中各个比赛的信息

def get_message_url(url):
   web_data = requests.get(url)
   soup = BeautifulSoup(web_data.text, 'lxml')
   titles = soup.select(".xld .xs2_tit a")
   views = soup.select("span.chakan")
   post_times = soup.select("div.list_info")
   for title, view, post_time in zip(titles, views, post_times):
       data = {
           "标题": title.get_text(),
           "浏览量": view.get_text().strip(),
           "发布时间": post_time.get_text().strip().split(" ")[0],
           "链接": title.get("href")
      }
       print(data)

The sixth day of Crawler learning的更多相关文章

  1. The fifth day of Crawler learning

    使用mongoDB 下载地址:https://www.mongodb.com/dr/fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl ...

  2. The fourth day of Crawler learning

    爬取58同城 from bs4 import BeautifulSoupimport requestsurl = "https://qd.58.com/diannao/35200617992 ...

  3. The third day of Crawler learning

    连续爬取多页数据 分析每一页url的关联找出联系 例如虎扑 第一页:https://voice.hupu.com/nba/1 第二页:https://voice.hupu.com/nba/2 第三页: ...

  4. The second day of Crawler learning

    用BeatuifulSoup和Requests爬取猫途鹰网 服务器与本地的交换机制 我们每次浏览网页都是再向网页所在的服务器发送一个Request,然后服务器接受到Request后返回Response ...

  5. The first day of Crawler learning

    使用BeautifulSoup解析网页 Soup = BeautifulSoup(urlopen(html),'lxml') Soup为汤,html为食材,lxml为菜谱 from bs4 impor ...

  6. Machine and Deep Learning with Python

    Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...

  7. 深度学习Deep learning

    In the last chapter we learned that deep neural networks are often much harder to train than shallow ...

  8. [C2P2] Andrew Ng - Machine Learning

    ##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...

  9. [C2P3] Andrew Ng - Machine Learning

    ##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...

随机推荐

  1. sql:mysql:函数:TIMESTAMPDIFF函数实现TimeStamp字段相减,求得时间差

    函数内指定是minute,则最终结果value值的单位是分钟,如果函数内指定为hours,则最终结果value值单位为小时. //UPLOAD_TIME 减去 CREATE_DTTM 求得时间差,以分 ...

  2. codeblocs的安装使用

    安装后,上面菜单栏 点击“Setting --> Compiler” "Creat a new project"

  3. oracle函数 TO_DATE(X[,c2[,c3]])

    [功能]将字符串X转化为日期型 [参数]c2,c3,字符型,参照to_char() [返回]字符串 如果x格式为日期型(date)格式时,则相同表达:date x 如果x格式为日期时间型(timest ...

  4. re模块下的常用方法

    一  :  re模块的查找 findall  优先级查找  返回列表 找所有的匹配项(从大段的内容中找匹配到的项目) import re str = "qwer asdf zxcv qwer ...

  5. CF1238E.Keyboard Purchase 题解 状压/子集划分DP

    作者:zifeiy 标签:状压DP,子集划分DP 题目链接:https://codeforces.com/contest/1238/problem/E 题目大意: 给你一个长度为 \(n(n \le ...

  6. Linux中使用gcc编译文件

    一个项目中可能有多个cpp文件,在linux下编译执行过程如下: g++ main.cpp distance.cpp ./a.out 即可一起编译两个文件,然后执行该程序.

  7. Android Xutils框架使用问题及解决办法

    刚刚写了篇博客,提了下在使用XUtils时遇到的一个问题Android Xutils框架HttpUtil Get请求缓存问题 ,既然已经提起来这个问题,那我想了下,就把之前使用Xutils时遇到的几个 ...

  8. H3C IP的主要作用

  9. HTML静态网页--JavaScript-DOW操作

    1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Windows对象操作 一.属性和方法: 属性(值或者子对象): o ...

  10. 谈谈数据库的 ACID(转)

    一.事务 定义:所谓事务,它是一个操作序列,这些操作要么都执行,要么都不执行,它是一个不可分割的工作单位. 准备工作:为了说明事务的ACID原理,我们使用银行账户及资金管理的案例进行分析. 二.ACI ...