#!/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. C++的一种业务分发方案(另类的工厂模式)

    在C++中,传统的业务分发.总要写一大串的switch-case,并且每次添加新业务时.都要在原有的switch-case里加一个分支,这就违反了设计模式中的开放封闭原则. 下面这样的方案,就全然去除 ...

  2. for别名

    name:for(int i =0 ;i< a.length;i++){ System.out.println(i); for(int j =0;j<i;j++){ continue na ...

  3. linux中的目录配置

    一.权限对文件的重要性 1.r(read):可读取此文件的实际内容,读取文本文件的文字内容等. 2.w(write):可以编辑,新增或者是修改该文件的内容. 3.x(execute):该文件具有可以被 ...

  4. php数组·的方法-数组排序

    /* * * 数组排序函数*/ //asort() 数组元素值升序排序 //arsort() 降序 $arr7=array(1,23,65,34,3,2,3,34,453,54,456,65,5); ...

  5. 08-----pymysql模块使用

    pymysql的下载和使用 exctue() 之sql注入 增.删.改:conn.commit() 查:fetchone.fetchmany.fetchall   一.pytmysql的下载和使用  ...

  6. cookie 跨域访问

    废话不知道该说些什么...先看代码吧. cookie 是浏览器保存在用户计算机上的少量数据 //读取cookie function getCookie(name) { var arr, reg = n ...

  7. python迭代器、生成器、列表推倒式

    创建迭代器: iter( ): 创建迭代器 next( ): 返回迭代器的下一个element(元素) 实例题: >>> list = [1,2,3,4] >>> ...

  8. spring mvc源码分析

    1.传统xml配置方式 web.xml里面配置:org.springframework.web.servlet.DispatcherServlet,处理项目的spring配置文件:classpath* ...

  9. Android NDK开发 Android Studio使用新的Gradle构建工具配置NDK环境(一)

    本文主要讲述了如何如何在Android Studio使用新的Gradle构建工具配置NDK环境,现在把相关的步骤整理出来分享给Android程序员兄弟们,希望给他们在配置NDK环境时带来帮助. 从An ...

  10. RTT设备与驱动之串口

    有一般收发.中断方式.DMA方式: rt_device_t rt_device_find(const char* name); rt_err_t rt_device_open(rt_device_t ...