MENU

Category: Python基础 »

urllib、request模块

urllib 模块

urllib.request

import urllib.request
req = urllib.request.urlopen("http://ops.attacker.club/")
data = req.read()
print (data)


"""
字符串变量 = file.read() #读取全部内容
列表变量 = file.readlines() #读取全部内容
字符串变量 = file.readline() #读取文件的一行内容
"""

下载html

import urllib.request
req = urllib.request.urlopen("http://ops.attacker.club/")
data = req.read().decode('UTF-8')


with open('index.html','w') as  f:
    f.write(data)

Read More

python - - set 集合

set 集合

例子

a=[1,2,3,4]
b=(3,4,5,6)
print ("a类型",type(a),"\nb类型:",type(b))

a类型 <class 'list'>
b类型: <class 'tuple'>

Read More

pip 相关

安装pip

setuptools、pip
https://pypi.python.org/pypi/pip#downloads
https://pypi.python.org/pypi/setuptools

yum

yum  install python-pip
#pip2
python setup.py install

Read More