Python3爬虫04(其他例子,如处理获取网页的内容)
#!/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(其他例子,如处理获取网页的内容)的更多相关文章
- Python获取网页指定内容(BeautifulSoup工具的使用方法)
Python用做数据处理还是相当不错的,如果你想要做爬虫,Python是很好的选择,它有很多已经写好的类包,只要调用,即可完成很多复杂的功能,此文中所有的功能都是基于BeautifulSoup这个包. ...
- telnet建立http连接获取网页HTML内容
利用telnet可以与服务器建立http连接,获取网页,实现浏览器的功能.它对于需要对http header进行观察和测试到时候非常方便.因为浏览器看不到http header. 步骤如下: 1. 运 ...
- 黄聪:C#获取网页HTML内容的三种方式
C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse. 方法一:使用WebClient static void ...
- 【Python3 爬虫】16_抓取腾讯视频评论内容
上一节我们已经知道如何使用Fiddler进行抓包分析,那么接下来我们开始完成一个简单的小例子 抓取腾讯视频的评论内容 首先我们打开腾讯视频的官网https://v.qq.com/ 我们打开[电视剧]这 ...
- C++ 与 php 的交互 之----- C++ 获取 网页文字内容,获取 php 的 echo 值。
转载请声明出处! http://www.cnblogs.com/linguanh/category/633252.html 距离上次 谈 C++ 制作json 或者其他数据传送给 服务器,时隔两个多月 ...
- [python]获取网页中内容为汉字的字符串的判断
实际上是这样,将获取到网页中表单内容与汉字字符串作比较,即: a = request.POST['a'] if a == '博客园': print 'ok' else: print 'false' a ...
- 使用SOCKET获取网页的内容
使用fsockopen()函数来实现获取页面信息,完整代码如下 //设置字符集(由于要抓取的网易网站字符集编码是gbk编码) header("content-type:text/html;c ...
- C++ 与 php 的交互 之----- C++ 异步获取 网页文字内容,异步获取 php 的 echo 值。
已搬迁至 http://www.cnblogs.com/linguanh/p/4543836.html
- php利用curl获取网页title内容
/**$html = curl_get_file_contents($url); $title = get_title_contents($html); var_dump($title);*/ fun ...
随机推荐
- [转]Groovy One Liners to Impress Your Friends
Link:http://arturoherrero.com/2011/06/04/10-groovy-one-liners-to-impress-your-friends/ I find that c ...
- 老男孩python作业8-学员管理系统
学员管理系统开发: 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上 ...
- P3172 [CQOI2015]选数(莫比乌斯反演)
[题目链接] https://www.luogu.org/problemnew/show/P3172 [题解] https://www.luogu.org/blog/user29936/solutio ...
- 解决SharePoint2013产品过期问题
作者:huangtao2011 引用:http://blog.csdn.net/huangtao2011/article/details/27528101 今天使用SharePoint 2013创建页 ...
- Experimental Educational Round: VolBIT Formulas Blitz K
Description IT City company developing computer games decided to upgrade its way to reward its emplo ...
- hdu 1556 涂气球 线段树(区间更新~对区间[x,y]更新,求任意节点被更新的次数)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- SQLServer连接查询之Cross Apply和Outer Apply的区别及用法
https://blog.csdn.net/wikey_zhang/article/details/77480118 先简单了解下cross apply的语法以及会产生什么样的结果集吧! 示例表: S ...
- python学习2(转载)
一.流程控制之while循环 语法:while 条件: 循环体else: else语句(当条件不成立的时候执行这里 和break没关系) 判断条件是否成立. 如果成立执行循环体.然后再次判断条件,.. ...
- eclipse 快捷键使用日志
Ctrl+Shift+F 格式化代码 Ctrl+Shift+O 快速导入资源包 Ctrl+m 最大化/最小化当前窗口(全屏/还原)
- Django-5.1 模型层 单表操作
7.1 ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开 ...