python3爬虫例子02(获取个人博客园的文章信息)

news/2024/7/19 10:37:20 标签: 爬虫, python
#!/usr/bin/env python
# -*- coding:UTF-8 -*-

import requests
from bs4 import BeautifulSoup

res=requests.get("https://www.cnblogs.com/NiceTime/")
# c=res.content
c=res.text
# print(c)

#获取文章日期
soup=BeautifulSoup(c,"html.parser")

postday=soup.find_all(class_="dayTitle")
# for i in postday:
# pday=i
# print(pday.a.string)

#获取文章标题
posttitle=soup.find_all(class_="postTitle")
# for i in posttitle:
# ptitle=i
# print(ptitle.a.string)

#获取文章摘要
postcorn=soup.find_all(class_="c_b_p_desc")
# for i in postcorn:
# ptitle=i
# print(pcorn.contents[0])

for day,title,corn in zip(postday,posttitle,postcorn):
# pcorn=i
print(day.a.string)
print(title.a.string)
print(corn.contents[0].string)
print("")


转载于:https://www.cnblogs.com/NiceTime/p/10070177.html


http://www.niftyadmin.cn/n/687768.html

相关文章

[整理]一个有关Latch(锁存器)的有趣问题

起源 今天诳论坛,突然发现了一个有关latch的问题,由于对D Flip-Flop和Latch还有些疑问,就点击了进去,一看果然有些意思,也挺有学习意义的,于是本文就诞生了。喊出口号~Just note it. 有意思的问题图 两个问…

linux运维基础篇 unit10

10.系统日志1.系统日志默认分类/var/log/messages ##系统服务及日志,包括服务的信息,报错等等/var/log/secure ##系统认证信息日志/var/log/maillog ##系统邮件服务信息/var/log/cron ##系统…

php 批量插入mysql_PHP批量插入百万数据,php mysql pdo插入百万数据

最近做项目遇到一个小问题,php批量插入大量数据,如果使用for循环来进行插入无疑是很sb的形为,拼接成一条Sql语句,将很好的解决问题一、使用pdo进行数据插入set_time_limit(0);$dbmsmysql; //数据库类型$hostlocalhost; //数据…

python3爬虫03(find_all用法等)

#read1.html文件# <html><head><title>The Dormouses story</title></head># <body># <p class"title"><b>The Dormouses story</b></p>## <p class"story">Once upon a time there we…

希赛和51cto哪个好_软考哪个好?哪个更好考?答案在这!

希赛软考之家关注我们&#xff0c;顺利取证▲点击蓝字关注&#xff0c;获取更多资讯软考有初、中、高三个级别&#xff0c;每个级别又有多个资格考试项目&#xff0c;因此很多考生在报名的时候不知道到底该报考哪个级别的资格&#xff0c; 那么到底考哪个好呢&#xff1f;◆ ◆…

python基础-修改haproxy配置文件

需要掌握的知识&#xff1a; 1、函数 2、文件处理 3、tag的用法 4、程序的解耦 需求&#xff1a; 1&#xff1a;查询 2&#xff1a;添加 3&#xff1a;删除 4&#xff1a;修改 5&#xff1a;退出 haproxy.conf 配置文件内容&#xff1a; 1 global2 log 127.0.0.1 local…

python中常见单词意思_Python中经常使用的单词

您可以先定义一个函数来获取字符串中的所有k-mer&#xff1a;def get_all_k_mer(string, k1):length len(string)return [string[i: i k] for i in xrange(length-k1)]然后你可以使用collections.Counter来计算每个k-mer的重复次数&#xff1a;>>> from collections …

linux运维基础篇 unit12

12.不同系统之间的文件传输1.文件归档1.文件归档&#xff0c;就是把多个文件变成一个归档文件2.tarc #创建f ##指定归档文件名称t ##显示归档文件中的内容r ##向归档文件中添加文件--ge…