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 ...
随机推荐
- Solr学习笔记(3) —— SolrJ管理索引库&集群
一.什么是SolrJ solrj是访问Solr服务的java客户端,提供索引和搜索的请求方法,SolrJ通常嵌入在业务系统中,通过SolrJ的API接口操作Solr服务,如下图: 二.SolrJ的基本 ...
- freemarker macro 使用
转载... macro, nested, return语法 <#macro name param1 param2 ... paramN>...<#nested loopvar1, l ...
- 关于 java中的SecureRandom在linux中每次生成不同结果
使用AES算法的时候,会发现下面的代码在windows每次产生确定的结果,但Linux就不同,导致无法正确解密 public static String encrypt(String content, ...
- Web开发中FormData对象的使用
参考: FormData 对象的使用 - Web API 接口 | MDN
- 第十章:DOM
<div class="wrap"> <ul id="ul"> <li>01</li> <li>02 ...
- SQL SERVER linked server Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
昨天创建了一个View, 这个view是一系列的表达式(CTE)组成,封装了好多的业务逻辑,简化下语句如下 ;with CTE AS( ...) SELECT a.company_id ,b.comp ...
- Jmeter录制pc脚本
1.打开jmeter后可以看到左边窗口有个“测试计划”和“工作台”,右键“测试计划”,添加 Threads(Users) →线程组,再右键 线程组→添加 配置元件→Http请求默认值 Http请求默认 ...
- 性能测试工具LoadRunner08-LR之Virtual User Generator 检查点
步骤: 1.点击Vuser--->Run-Time Settings 2.点击Preferences--->Enable Image and text check 3.点击Content ...
- python3+Appium自动化11-data数据封装之python读取csv文件
使用背景 实际项目中,我们的测试数据可能存储在一个数据文件中,如txt.excel.csv文件类型.我们可以封装一些方法来读取文件中的数据来实现数据驱动 enumerate()简介 enumerate ...
- [转]关于Jquery的DataTables里TableTools的应用
本文转自:http://147068307.iteye.com/blog/1700516 最近在产品中使用了TableTools这个工具,主要用来实现导出和复制功能. 但是在实际的运用中出现了以下相关 ...