perloader

Python 片段

打印网页源代码 import urllib.request response = urllib.request.urlopen(“http://027886.xyz/”) print (response.read().decode(‘utf-8’)) 设置头部header head = {} head[‘User-Agent’] = ‘Mozilla ……’ head[‘Referer’] = ‘http://027886.xyz’ POST传送数据 import urllib.parse data = {} data[‘f’] = ‘undefined’ data[‘t’] = ‘undefined’ data[‘w’] = content 词霸翻译示例 import urllib.request import urllib.parse import json import time while True: content = input(‘请输入需要翻译的中文内容(输入“q!”退出程序):’) if content == ‘q!’: break url = […]

.

Read more

python 笔记

1.sum()函数接受一个list作为参数,并返回list所有元素之和。请计算 1*1 + 2*2 + 3*3 + … + 100*100。 L = [] x = 1 while x <= 100: L.append(x*x) x += 1 print (sum(L)) append() 方法用于在列表末尾添加新的对象。 以下实例展示了 append()函数的使用方法: #!/usr/bin/python aList = [123, ‘xyz’, ‘zara’, ‘abc’]; aList.append( 2009 ); print “Updated List : “, aList; 以上实例输出结果如下: Updated List : [123, ‘xyz’, ‘zara’, ‘abc’, 2009] […]

.

Read more

centos 6.x yum 安装LAMP

CentOS默认yum源软件版本太低了 本次安装最终为: CentOS release 6.8 (Final) PHP 5.4.45   1、配置防火墙,开启80端口、3306端口 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT :wq! #保存退出 注意需要添加至22端口的位置 即 -A INPUT -m state –state NEW -m tcp -p tcp –dport […]

.

Read more

CentOS 版本查询

1. 查看 Linux Kernel 版本 $uname -r 2. 查看 CentOS 版本 $cat /etc/redhat-release 3. 查看 PHP 版本 $php -v 4. 查看 MySQL 版本 $mysql -v 5. 查看 Apache 版本 $rpm -qa httpd

.

Read more

Centos6下安装Python3.5

centos6.6自带的Python2.6,不能够用yum安装,那么只能从源码编译安装。 yum install gcc -y yum install openssl-devel 如果没有安装openssl-devel,在安装过程中pip无法安装 wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz tar zxvf Python-3.5.1.tgz cd Python-3.5.1 ./configure&& make && make install 将 python3.5 链接到python3命令 whereis python 会输出所有Python的目录 /usr/local/bin/python3.5 sudo ln -s /usr/local/bin/python3.5 /usr/bin/python3 就可以把Python3.5链接到Python3了 安装完后就可以输入# python3 看看是否安装完成吧 python3 –version 如果需要将python命令重新指向python2.6 sudo rm /usr/bin/python sudo ln -s /usr/bin/python2.6 /usr/bin/python sudo rm /usr/bin/python sudo ln -s /usr/local/bin/python3.5 […]

.

Read more

Python3 第一个小爬虫:抓取页面

查看: first-python-script #encoding:utf-8 import urllib.request as request #导入urllib模块 import urllib.parse as parse import string print(“”” +++++++++++++++++++++++ For test only version: python3.3 +++++++++++++++++=++++ “””) def baidu_tieba(url, begin_page, end_page): for i in range(begin_page, end_page + 1): sName = ‘c:/ChromeDL/PPyy/000/test/’+str(i).zfill(5)+’.html’ print(‘正在下载第’+str(i)+’个页面, 并保存为’+sName) m = request.urlopen(url+str(i)).read() with open(sName,’wb’) as file: file.write(m) file.close() if __name__ == “__main__”: url = “http://tieba.baidu.com/p/” begin_page […]

.

Read more

python 学习

安装的是python 3.3 http://www.python.org/ftp/python/3.3.5/python-3.3.5.amd64.msi ‘Python’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。 需要手动添加环境变量:鼠标右键我的电脑 -> 属性 -> 点击高级系统设置 -> 点击环境变量 -> 点击PATH -> 在最后面加上我们的Python安装路径 -> 点击确定。 在这个过程中需要注意的问题是,添加PATH路径的时候,要在最后面添加一个分号。 下载pip-8.1.2.tar.gz至Python安装目录,解压 用CMD控制台进入解压目录 python setup.py install 显示 ImportError: No module named ‘setuptools’ 下载https://bootstrap.pypa.io/ez_setup.py C:\ChromeDL python ez_setup.py 再试一次 pip安装成功了 ‘pip’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。 按照之前介绍的添加环境变量的方法,我们在PATH最后添加: C:\Python33\Scripts; 重启CMD,到现在才算完整安装好了pip。 pip install BeautifulSoup4 LDLE里面 import bs4 没有报错。    

.

Read more

download chrome version 24.9

Instructions: 1. First, download the Chrome version 24.0 installer file on THIS LINK 2. Next, you need to uninstall the current Chrome version. Do that in the Control Panel (Start > Control Panel > Uninstall a program) 3. Once uninstalled, you need to remove the Chrome user folder associated with that version as well. The […]

.

Read more

开启mysql的慢查询

开启mysql的慢查询 用命令开启慢查询 set global slow_query_log=ON; set global long_query_time=1; set global log_queries_not_using_indexes = 1; 查看是否成功 show variables like “%slow%”; show variables like ‘log_queries_not_using_indexes’; show global status like ‘%slow%’; 看看慢查询的记录数     或者 修改mysql的配置文件my.cnf long_query_time = 2 log-slow-queries = /usr/local/mysql/mysql-slow.log     MySQL查询缓存设置 select @@query_cache_type; show variables like ‘have_query_cache’; set @@global.query_cache_size=400000000; select @@global.query_cache_size; select @@global.query_cache_limit;   show […]

.

Read more

杀死包含某关键字的所有进程

httpd服务突然启动不了 (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs [FAILED]   ps -aux | grep http ps -ef|grep httpd|grep -v grep|cut -c 9-15|xargs kill -9 service httpd restart

.

Read more
xyz