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来实现网络爬虫的基 ...
随机推荐
- windows API 开发飞机订票系统 图形化界面 (一)
去年数据结构课程设计的作品,c语言实现,图形化界面使用windows API实现. 首发在我csdn博客:http://blog.csdn.net/u013805360/article/details ...
- 微信小程序开发:http请求
在微信小程序进行网络通信,只能和指定的域名进行通信,微信小程序包括四种类型的网络请求. 普通HTTPS请求(wx.request) 上传文件(wx.uploadFile) 下载文件(wx.downlo ...
- Mtk Ft6306 touch 驱动 .
1.1. MTK Touch 驱动的组成Mtk Touch driver 驱动包括:Mtk platform 虚拟平台设备驱动.Module touch IC 驱动.Input subsys ...
- [BZOJ 1295][SCOI2009]最长距离(SPFA+暴力)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1295 分析:很巧妙的一道spfa从搜索的角度是搜索在所有1中搜索删除哪T个1,对整个图询问,这 ...
- VMware v12.1.1 专业版以及永久密钥
热门虚拟机软件VMware Workstation 现已更新至v12.1.1 专业版!12.0属于大型更新,专门为Win10的安装和使用做了优化,支持DX10.4K高分辨率显示屏.OpenGL 3.3 ...
- 解决 pathForResource 返回 nil的问题
点击(此处)折叠或打开 NSString* path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@&quo ...
- hdu3613 扩展KMP
#include<stdio.h> #include<string.h> #define maxn 501000 char s[maxn],t[maxn]; int next[ ...
- Spring-dispatcherServlet
对于分析SpringMVC,其实就是遵循Servlet世界里最简单的法则“init-service-destroy”. 对于分析SpringMVC的初始化流程,就是分析DispatcherServle ...
- Java-ArrayList
package 集合类.list类; /** * System.Collections.ArrayList类是一个特殊的数组.通过添加和删除元素,就可以动态改变数组的长度. 一.优点 1.支持自动改变 ...
- 图解Android - Looper, Handler 和 MessageQueue
Looper, Handler 和 MessageQueue 是Android 的异步消息处理机制