#!/usr/bin/env python
# -*- coding:utf-8 -*- import os
import re
import requests
from bs4 import NavigableString
from bs4 import BeautifulSoup res=requests.get("https://www.qiushibaike.com/")
qiushi=res.content
soup=BeautifulSoup(qiushi,"html.parser")
duanzis=soup.find_all(class_="content")
for i in duanzis:
duanzi=i.span.contents[0]
# duanzi=i.span.string
print(duanzi)
# print(i.span.string) res=requests.get("http://699pic.com/sousuo-218808-13-1-0-0-0.html")
image=res.content
soup=BeautifulSoup(image,"html.parser")
images=soup.find_all(class_="lazy") for i in images:
original=i["data-original"]
title=i["title"]
# print(title)
# print(original)
# print("")
try:
with open(os.getcwd()+"\\jpg\\"+title+'.jpg','wb') as file:
file.write(requests.get(original).content)
except:
pass r = requests.get("http://699pic.com/sousuo-218808-13-1.html")
fengjing = r.content
soup = BeautifulSoup(fengjing, "html.parser")
# 找出所有的标签
images = soup.find_all(class_="lazy")
# print images # 返回list对象 for i in images:
jpg_rl = i["data-original"] # 获取url地址
title = i["title"] # 返回title名称
print(title)
print(jpg_rl)
print("") r = requests.get("https://www.qiushibaike.com/")
r=requests.get("http://www.cnblogs.com/nicetime/")
blog=r.content
soup=BeautifulSoup(blog,"html.parser")
soup=BeautifulSoup(blog,features="lxml")
print(soup.contents[0].contents) tag=soup.find('div')
tag=soup.find(class_="menu-bar menu clearfix")
tag=soup.find(id="menu")
print(list(tag)) tag01=soup.find(class_="c_b_p_desc") print(len(list(tag01.contents)))
print(len(list(tag01.children)))
print(len(list(tag01.descendants))) print(tag01.contents)
print(tag01.children)
for i in tag01.children:
print(i) print(len(tag01.contents)) for i in tag01:
print(i) print(tag01.contents[0].string)
print(tag01.contents[1])
print(tag01.contents[1].string) url = "http://www.dygod.net/html/tv/oumeitv/109673.html"
s = requests.get(url)
print(s.text.encode("iso-8859-1").decode('gbk'))
res = re.findall('href="(.*?)">ftp',s.text)
for resi in res:
a=resi.encode("iso-8859-1").decode('gbk')
print(a)

Python3爬虫04(其他例子,如处理获取网页的内容)的更多相关文章

  1. Python获取网页指定内容(BeautifulSoup工具的使用方法)

    Python用做数据处理还是相当不错的,如果你想要做爬虫,Python是很好的选择,它有很多已经写好的类包,只要调用,即可完成很多复杂的功能,此文中所有的功能都是基于BeautifulSoup这个包. ...

  2. telnet建立http连接获取网页HTML内容

    利用telnet可以与服务器建立http连接,获取网页,实现浏览器的功能.它对于需要对http header进行观察和测试到时候非常方便.因为浏览器看不到http header. 步骤如下: 1. 运 ...

  3. 黄聪:C#获取网页HTML内容的三种方式

    C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse. 方法一:使用WebClient static void ...

  4. 【Python3 爬虫】16_抓取腾讯视频评论内容

    上一节我们已经知道如何使用Fiddler进行抓包分析,那么接下来我们开始完成一个简单的小例子 抓取腾讯视频的评论内容 首先我们打开腾讯视频的官网https://v.qq.com/ 我们打开[电视剧]这 ...

  5. C++ 与 php 的交互 之----- C++ 获取 网页文字内容,获取 php 的 echo 值。

    转载请声明出处! http://www.cnblogs.com/linguanh/category/633252.html 距离上次 谈 C++ 制作json 或者其他数据传送给 服务器,时隔两个多月 ...

  6. [python]获取网页中内容为汉字的字符串的判断

    实际上是这样,将获取到网页中表单内容与汉字字符串作比较,即: a = request.POST['a'] if a == '博客园': print 'ok' else: print 'false' a ...

  7. 使用SOCKET获取网页的内容

    使用fsockopen()函数来实现获取页面信息,完整代码如下 //设置字符集(由于要抓取的网易网站字符集编码是gbk编码) header("content-type:text/html;c ...

  8. C++ 与 php 的交互 之----- C++ 异步获取 网页文字内容,异步获取 php 的 echo 值。

    已搬迁至 http://www.cnblogs.com/linguanh/p/4543836.html

  9. php利用curl获取网页title内容

    /**$html = curl_get_file_contents($url); $title = get_title_contents($html); var_dump($title);*/ fun ...

随机推荐

  1. nginx的配置文件(反向代理和主配置)

    配置文件保存,是为了工作方便.特别是优化好的配置.我们基本可以直接复制粘贴.这样做可以快速的完成手上的工作!! vim nginx.conf user nginx; worker_processes ...

  2. shell脚本学习一

    shell脚本是一种程序与linux内核的语言: 第一个shell脚本: #!/bin/bash echo "cxy" 就是输出cxy 如何执行这个脚本呢: cd demo 进入s ...

  3. centos7上面关闭防火墙

    CentOS 7.0默认使用的是firewall作为防火墙:若没有启用iptables 作为防火墙,则使用以下方式关闭防火墙: systemctl stop firewalld.service 关闭开 ...

  4. 爬虫框架urllib 之(三) --- urllib模块

    Mac本 需导入ssl import ssl ssl._create_default_https_context = ssl._create_unverified_context  urllib.re ...

  5. 树莓派使用 PPA 安装 Java 8

    前言 在树莓派上安装 Java 8,与这篇的操作类似,不过树莓派不支持用 add-apt-repository 自动添加 webupd8team 的源,所以要手动添加. 步骤 在 /etc/apt/s ...

  6. ubuntu下vnstat监控网卡流量

    vnstat使用 vnstat 是另一个可以用来监视带宽使用量的程序.它比ipac-ng更简单易用. vnstat的一个优点是它不是一个运行的守护程序,所以它几乎不占用内存.它由 cron 任务创建, ...

  7. Hibernate上传数据到数据库,从数据库读取数据到本地模板代码

    1.Hibernate上传数据到数据库: //创建一个session对象 Session session1=HibernateTools.getSession(); //Fenciresult数据库表 ...

  8. Kibana6.x.x——导航权限控制入门

    按如下图所示设置: 用该用户登录后,界面如图所示: 但遗憾的是,根据官方论坛的说法,其它的导航隐藏控制,暂时还不支持. 参考:https://discuss.elastic.co/t/hide-ina ...

  9. 【ABP开发】:asp.net core 中使用mysql

    EntityFrameworkCore项目--Nuget包管理,卸载包: Microsoft.EntityFrameworkCore.SqlServer: EntityFrameworkCore项目和 ...

  10. 毕业设计 python opencv实现车牌识别 颜色判断

    主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuow ...