Python ===if while for语句 以及一个小小网络爬虫实例
if分支语句
>>> count=89
>>> if count==89:
print count
89 #单分支
>>>
#coding:utf-8
count=int(raw_input('请输入一个数字'))
print count
if count>80:
print '比80大'
else:
if count<80:
print ‘比80小’ #多分支
=======自定义函数 while if else===========
#coding:utf-8
count=int(raw_input('请输入一个数字'))
print count
if count>80:
print '比80大'
else:
print '比80小'
print 'End'
sex=raw_input('请输入您的性别')
def inputsex(sex):
while(sex!='male' and sex!='female'):
print sex
sex=raw_input('请输入性别为male 或者 female')
if sex=='male':
print 'Gentleman!'
else:
if sex=='female':
print 'Lady'
inputsex(sex)
=====if else的关系表达式bool判断 非0即真!=====
#coding:utf-8
if True:
print '1True'
else:
print 'False'
if 0:
print '2True'
else:
print '2False'
if 1:
print '3True'
else:
print '3False'
if 298:
print '4True'
else:
print '4False'
if -2:
print '5True'
else:
print '5False'
1True
2False
3True
4True
5True
If
if (A and B):
if (A or B):
if not A:
=======================while循环体========================
========网络刷浏览量的爬虫=======
#coding:utf-8
import time
import webbrowser
import os
import random
count=random.ranint(2,8)
i=1
j=0
while j<count:
while i<=3:
webbrowser.open_new_tab('www.baidu.com')
i=i+1
time.sleep(3)
else:
os.system('taskkill /F /IM iexplore.exe')
j=j+1
#windows下用taskkill 用的时候上网搜一下
#linux系统下用kill -pid 或者 killall chrome
#ranint就是随机整数
=======for循环语句============
for val in sth. 其中val不用预先声明
For遍历字符串
#coding:utf-8
s1='www.baidu.com'
i=0
for n in s1:
print format(i,'2d'),n
i=i+1
else:
print 'out for'
#format(i,’2d’)使i占两个输出位
For遍历list列表数组
#coding:utf-8
list1=[0,11,45,'dkfjah',12.5] 列表类型
i=0
for val in list1:
print format(i,'2d'),val
i=i+1
也可以直接写成这样
#coding:utf-8
i=1
for val in [11,23,0,'dfadf','国语',12.45]:
print format(i,'2d'),val
i=i+1
将字符串转换成list list(str)
#coding:utf-8
s1='www.baidu.com'
i=1
list1=list(s1)
print list1
for val in list1:
print format(i,'2d'),val
i=i+1
元组 for遍历元组tuple
#coding:utf-8
#用圆括号括起来的是元组,元组中的数据只可读,不可修改。
tup=(1,2,3,4,5) 元组类型
for t in tup:
print t
else:
print 'out tup'
for遍历文件 for val in file.readlines()
#coding:utf-8
#如果所读的文件与此py程序文件所在地址一样,则直接写文件名
for s in open('11.txt','r').readline():
print s
li3=open('11.txt','r').readlines()
for a in open('11.txt','r').readlines():
open('tmp.txt','a+').write(a) #a+是追加写入 r 读 w写 w+如果没有此文件先创建再写入
print a
print len(li3)
#len(li3)输出列表有多长 这里即文章有多少行
#readline()返回字符串 默认返回第一行
#readlines()返回list 默认为文件中所有行的list
#用help(file.readline)查看帮助
Python 爬虫如何获取 JS 生成的 URL 和网页内容?
例如看页面是用Ajax请求一个JSON文件,我就先爬那个页面,获取Ajax所需的参数,然后直接请求JSON页,然后解码,再处理数据并入库。
如果你直接运行页面上所有js(就像浏览器做的那样),然后获取最终的HTML DOM树,这样的性能非常地糟糕,不建议使用这样的方法。因为Python和js性能本身都很差,如果这样做,会消耗大量CPU资源并且最终只能获得极低的抓取效率。
Python ===if while for语句 以及一个小小网络爬虫实例的更多相关文章
- Python 利用Python编写简单网络爬虫实例3
利用Python编写简单网络爬虫实例3 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://bbs.51testing. ...
- Python 利用Python编写简单网络爬虫实例2
利用Python编写简单网络爬虫实例2 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://www.51testing. ...
- python爬虫系列(1)——一个简单的爬虫实例
本文主要实现一个简单的爬虫,目的是从一个百度贴吧页面下载图片. 1. 概述 本文主要实现一个简单的爬虫,目的是从一个百度贴吧页面下载图片.下载图片的步骤如下: 获取网页html文本内容:分析html中 ...
- Python Socket,How to Create Socket Server? - 网络编程实例
文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programin ...
- [Python] 前程无忧招聘网爬取软件工程职位 网络爬虫 https://www.51job.com
首先进入该网站的https://www.51job.com/robots.txt页面 给出提示: 找不到该页 File not found 您要查看的页已删除,或已改名,或暂时不可用. 请尝试以下操作 ...
- 《Python编程》课程报告 python技术在数据分析中的应用之网络爬虫
摘要:... 2 1 引言 :... 2 1.1课题研究背景和研究现状... 2 1.1.1课题背景和目的... 3 1.1.2研究现状... 4 1.1.2.1语言... 4 1.1 ...
- Python数据抓取(2) —简单网络爬虫的撰写
(一)使用Requests存储网页 Requests 是什么?网络资源(URLs)抓取套件 优点? 改善urllib2的缺点,让使用者以最简单的方式获取网络资源 可以使用REST操作(POST,PUT ...
- 一个使用 asyncio 开发的网络爬虫(译文)
原文地址:https://www.aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html 作者简介 A. Jesse Jiryu ...
- [Python]网络爬虫( 连载:大牛汪海 )
汪海个人博客:http://blog.callmewhy.com/ Python爬虫专栏,汪海专栏 Python爬虫入门教程 简单的介绍如何使用Python的相关模块如urllib2来实现网络爬虫的基 ...
随机推荐
- C#基础之IL
1.实例解析IL 作为C#程序员,IL的作用不言而喻,首先来看一个非常简单的程序和它的IL解释图,通过这个程序的IL指令来简单的了解常见的IL指令是什么意思. class Program { stat ...
- zoeDylan.ImgChange 图片切换插件
墨芈深夜发布插件——图片切换 附上下载地址:http://pan.baidu.com/s/17kKF3共享天地/[墨芈 插件]zoeDylan Plugins Code JS (function ($ ...
- jdbc基础 (四) 批处理
批处理,就是字面上的意思,一次性处理一批sql语句. 直接看例子吧: package com.cream.ice.jdbc; import java.sql.Connection; import ja ...
- Object C学习笔记15-协议(protocol)
在.NET中有接口的概念,接口主要用于定义规范,定义一个接口关键字使用interface.而在Object C 中@interface是用于定义一个类的,这个和.NET中有点差别.在Object C中 ...
- 第十六课:一些奇葩的元素节点object,video
object元素 object这个元素,现在前端很少用到,但是像flash,svg等奇葩元素,必须嵌套在object对象元素中.现代浏览器用video,canvas代替这些元素. 之前做过图表和地图的 ...
- Linux svn 回滚版本库
Linux代码 svn up Index/ 然后找出要撤销的确切版本: Linux代码 svn log --limit 10 Index/tpl/css/global.css 根据log怀疑是 ...
- 【The final】软件工程实践总结
软件工程就这么告一段落了,竟然有那么一丢丢的舍不得-- 一.为拖延找的种种借口 [首先声明]以下纯粹是个人吐槽,仅作记录以便日后自己可以回顾一下往昔罢了,可以直接忽略,跳到第二大点:我的拖延之 ...
- WampServer集成环境安装与配置
实习到了第三个礼拜了,原来我们小组是以开发php为主的,我们项目的服务器也是用php做的,因此我觉得很有必要学一下php的相关知识,首先当然是搭建环境了,写篇博客分享下经验. 目录: 一.软件下载 二 ...
- Spring 常用注解
用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册 <context:component-scan base-package=”pagkage1[, ...
- ios消息
Class typedef struct objc_class *Class; struct objc_class { Class isa OBJC_ISA_AVAILABILITY; #if !__ ...