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 和网页内容?

我是直接看js源码,分析完,然后爬的。
例如看页面是用Ajax请求一个JSON文件,我就先爬那个页面,获取Ajax所需的参数,然后直接请求JSON页,然后解码,再处理数据并入库。
如果你直接运行页面上所有js(就像浏览器做的那样),然后获取最终的HTML DOM树,这样的性能非常地糟糕,不建议使用这样的方法。因为Python和js性能本身都很差,如果这样做,会消耗大量CPU资源并且最终只能获得极低的抓取效率。

Python ===if while for语句 以及一个小小网络爬虫实例的更多相关文章

  1. Python 利用Python编写简单网络爬虫实例3

    利用Python编写简单网络爬虫实例3 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://bbs.51testing. ...

  2. Python 利用Python编写简单网络爬虫实例2

    利用Python编写简单网络爬虫实例2 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://www.51testing. ...

  3. python爬虫系列(1)——一个简单的爬虫实例

    本文主要实现一个简单的爬虫,目的是从一个百度贴吧页面下载图片. 1. 概述 本文主要实现一个简单的爬虫,目的是从一个百度贴吧页面下载图片.下载图片的步骤如下: 获取网页html文本内容:分析html中 ...

  4. Python Socket,How to Create Socket Server? - 网络编程实例

    文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programin ...

  5. [Python] 前程无忧招聘网爬取软件工程职位 网络爬虫 https://www.51job.com

    首先进入该网站的https://www.51job.com/robots.txt页面 给出提示: 找不到该页 File not found 您要查看的页已删除,或已改名,或暂时不可用. 请尝试以下操作 ...

  6. 《Python编程》课程报告 python技术在数据分析中的应用之网络爬虫

      摘要:... 2 1       引言 :... 2 1.1课题研究背景和研究现状... 2 1.1.1课题背景和目的... 3 1.1.2研究现状... 4 1.1.2.1语言... 4 1.1 ...

  7. Python数据抓取(2) —简单网络爬虫的撰写

    (一)使用Requests存储网页 Requests 是什么?网络资源(URLs)抓取套件 优点? 改善urllib2的缺点,让使用者以最简单的方式获取网络资源 可以使用REST操作(POST,PUT ...

  8. 一个使用 asyncio 开发的网络爬虫(译文)

    原文地址:https://www.aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html 作者简介 A. Jesse Jiryu ...

  9. [Python]网络爬虫( 连载:大牛汪海 )

    汪海个人博客:http://blog.callmewhy.com/ Python爬虫专栏,汪海专栏 Python爬虫入门教程 简单的介绍如何使用Python的相关模块如urllib2来实现网络爬虫的基 ...

随机推荐

  1. webSocket实现web及时聊天的例子

    概述 websocket目前虽然无法普及应用,未来是什么样子,我们不得而知,但现在开始学习应用它,只有好处没有坏处,本随笔的WebSocket是版本13(RFC6455)协议的实现,也是目前webso ...

  2. Orchard使用Tags(标签)组织文本

    本文链接:http://www.cnblogs.com/souther/p/4517476.html 主目录 原文链接:http://docs.orchardproject.net/Documenta ...

  3. sublime2的一些基本常用的操作

    1.全局搜 ctrl shift f 如果你的快捷键有冲突的话,那么你在find的菜单中有find in file这个中找.

  4. 编写高质量代码改善C#程序的157个建议[10-12]

    前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议10.创建对象时需要考虑是否实现比较器 建议11.区别对待 ...

  5. linux 安装redmine 遇到的问题

    1.编译安装ruby-2.3.1时 需要先安装libyaml.libyaml-devel 2. 安装gem install rake ERROR: Loading command: install ( ...

  6. 【BZOJ 3524】【Poi2014】Couriers 可持久化线段树

    为什么这个主席树叫可持久化线段树,我不知道,具体得问达神.我无限T,然后DaD3zZ一针见血地指出了我的N*50爆内存导致无限编译超时O)ZO)ZO)Z真是太神啦.以图为鉴: 达神题解传送门:http ...

  7. vijos p1523 贪吃的九头龙 思考思考再思考,就荒废了4小时

    树形DP要有自己的风格,转二叉树是基础,考虑边界最头疼. #include<cstdio> #include<cstring> #include<algorithm> ...

  8. 使用Navicat远程管理OpenShift的数据库

    其实 phpMyAdmin 这个 web 端的 MySQL 数据库管理工具还是很好的,要不然也不会成为 MySQL 数据库的绝配.但是我想,很多人应该和重华一样,不太喜欢使用 web 端的工具,总觉得 ...

  9. 【poj1804】 Brainman

    http://poj.org/problem?id=1804 (题目链接) 题意 求逆序对 Solution1 归并排序. 每次合并时计算逆序对.  代码1 // poj1804 #include&l ...

  10. sqlserver字段类型详解

    抄了一篇不错的数据库类型,来自:http://www.cnblogs.com/andy_tigger/archive/2011/08/21/2147745.html bit 整型 bit数据类型是整型 ...