默认教学计划
931人加入学习
(16人评价)
简单学Python安全
价格 ¥ 399.00
该课程属于 高校公益行 | 网络安全实践训练营 请加入后再学习

                         requests_1

        requests库可以实现对一些网站的访问。

        安装:pip install request

        import requests

        print dir(requests)

        url="https://www.baidu.com"

        proxies={     #代理认证

        "http":"http://127.0.0.2:8000",

        "https":"http://127.0.0.2:8000",

}       

        r = requests.post(url, proxies=proxies, headers=headers, cookies=cookies, verify=False, data=payload)    #相当于在浏览其中输入该url

          r=requests.post(url)

          print r.status_code  #返回状态代码

          print r.content     #返回源代码,也可用text

          print r,request.headers  #查看请求头

          print r.headers               #返回响应包的头

          print r.request.body      #查看请求参数

          print r.encoding            #查看返回的编码格式

[展开全文]
暨南大学_planB · 2018-06-04 · 该任务已被删除 0

r=requests.get(url) 每次访问都是全新的访问没有cookie

 

r=requests.session()

rg=r.get(url)访问过后会有cookie保留,再进行

rg=r.get(url)会带上cookie进行访问

[展开全文]
GG_1 · 2018-07-18 · 该任务已被删除 0

[展开全文]
yilanere · 2018-05-30 · 该任务已被删除 0

 

 

[展开全文]
成长的小白 · 2018-08-02 · 该任务已被删除 0

help(list);查看详细的帮助文档。

dir(list);查看简略的帮助文档

str(int);    int(str);

数字与字符串之间的转换。

 

>>>s="www.baidu.com"

>>>l=s.split(".")

['www','baidu'.'com']

>>>".".join(l)

'www.baidu.com'

 

字典 转 列表

dict.items()    # dict是字典类型,返回列表类型

[展开全文]
cafuc_维新 · 2018-06-09 · 该任务已被删除 0

import requests

from bs4 import BeatuifulSoup

PATH = '' 绝对路径

url=''

def main(url):

r = requests.get(url)

soup = BeautifulSoup(r.content)

img_url=soup.find('img')['src'].encode('utf-8')

img_name = img_url[img_url.rfind('/')+1]

r = requests.get(img_url)

con = r.content

o = open(PATH + img_name,'w')

o.write(con)

o.close()

soup.find('img)['src'] = PATH + img_name

o = open(PAth + 'test.html','w')

o.write(sstr(soup))

o.close()

 

 

 

 

[展开全文]
成长的小白 · 2018-07-28 · 该任务已被删除 0

[展开全文]
yilanere · 2018-06-01 · 该任务已被删除 0

import json

dic={}

s=json.dumps(dic,indent=4) 将字典转换str  序列化 indent=4 四个缩进

json.loads(s) 将str转换为dict

developer.github.com

import requests

import json

key = 'baidu'

url=''

TOKEN =''

headers = {'Authentication':'token %s'%TOKEN}

params = {'per_page':10,'page':0}

 

 

 

 

 

[展开全文]
成长的小白 · 2018-07-26 · 该任务已被删除 0

subprocess 调用第三方库、文件

subprocess.call(['ls','-l'])  

subprocess.call('ls -l',shell=True) 调用系统shell

subprocess.check_call([])

三种对于返回值不同,处理方式不同

retcode = subprocess.check_out([]) 

以上都是父进程等待子进程结束

 

child = subprocess.Popen([])

subprocess.Popen('',shell=Ture)

child.wait()  设置超时时长

父进程等待子进程结束

输出

p = subprocess.Popen([],stdout=subprocess.PIPE)

print p.stdout.read()  

将输出结果放在管道里,只能放64kb

p = subprocess.Popen([],stdout=subprocess.PIPE)

stdout,stderr = p.communicate()

communicate数据放在内存中

p.poll()子进程状态   如果子进程结束了 返回None  结束 返回0

 

[展开全文]
成长的小白 · 2018-08-04 · 该任务已被删除 0

urrl,urrl2

[展开全文]
cafuc_维新 · 2018-06-11 · 该任务已被删除 0

import requests

dir(requests)  #查看模块方法

url = "https://www.baidu.com"

*************get::

代理认证

proxies = {

"http":"http://127.0.0.1:8080",

"https":"https://127.0.0.1:8080"}

 

r = requests.get(url,proxies,verify =False)

                          proxies  #代理

                          verify   #False ,不认证

r.txt                 #返回

r.content         #信息

r.requests.headers  #请求头

*********post请求::

r=requests.post(url,data,...headers,cookies)

data #待提交的数据

conn=resquests.session()

r = conn.get(url)

第二次访问时,会将第一次的cookies添加上去

 

[展开全文]
中石大_森林 · 2018-05-04 · 该任务已被删除 0

import  json

dict = {"name":"loop","age":"12"}

s = json.dumps(dict, indent=4)

将字典转成序列        indent  缩进

print  s

{     "age":"12",

      "name":"loop"

}

d = json.loads( s )   序列转成json

[展开全文]
中石大_森林 · 2018-05-04 · 该任务已被删除 0

import socket

socket.gethostname() 返回主机名

gethostbyname() 返回ip地址

gethostbyname_ex 返回 主机名 主机别名列表 ip地址

gethostbyaddr() 返回主机名

getservbyport(80,'tcp')  根据端口返回服务名

getservbyname('http','tcp;) 根据服务名返回端口

socket.socket(family,type)

family代表地址家族,可为AF_INET或AF_UNIX,AF_INET家族包括ip地址,AF_UNIX家族用于同一台机器上进程通信。socket.AF_INET指的是ipv4,socket.AF_INET6指的是ipv6。

type表示套接字类型,socket.SOCK_STREAM表示TCP,socket.SOCK_DGRAM表示UDP

模拟登陆安全牛

sock.connect(('edi.com',80))

sock.sendall(s)  发送

sock.recv(1024)  接受

sock.close()

print recv_data

https:

import ssl

sock = ssl.wrap_socket(socket.socket())

s.bind((host,port)) 绑定端口

s.listen(s)  监听

connection,address = s.accept()

调用accept时,socket会进入waiting状态,客户请求连接时,方法建立连接并返回服务器,accept返回一个含有两个元素的元祖(connection,address),第一个元素connection是新的socket对象,服务器必须经过他与客户通信,第二个元素address是客户机地址

 

 

 

[展开全文]
成长的小白 · 2018-07-30 · 该任务已被删除 0

练习:多线程对Ip进行tcp端口探测

import threading
import socket
imoprt time

#获得扫描ip
def getip():
    iplist = []
    o = open('ip.txt','r')   #现在是从文件中取出ip
    for ip in o.readlines():
        a = ip.strip()
        iplist.append(a)
    o.close()
    return iplist

#扫描函数
def scan(ip):
    s = socket(socket.AF_INET, socket.SOCK_STREAM)
    for port in xrange(1,65535):
        try:
            s.connect((ip,port))
            print 'open port!!'+ ip + '\t' + str(port)
        except:Exception,e:
            pass

#使用多线程进行扫描
def main():
    for ip in getip():#将每个参数生成一个对应的线程
         t = threading.Thread(target=scan,args=(ip,))
         threads.append(t)
    n = 0
    while True:
        if n == len(threads)
            break
        thread = threads[n]
        if threading.activeCount() < 10:
            print 'started ' + str(thread)
            thread.start()
            thread.join()
        else:
            n -=1
        n += 1
        print n
        time.sleep(2)
 '''   for thread in threads:
        if threading.activeCount() < 2:
            thread.start()
            thread.join()
            print 'started: ' + str(thread)
        else:
             pass
'''
 

if _name_ == "_main_):
    main()

 

[展开全文]
Johnny_s.h · 2018-09-04 · 该任务已被删除 0

im = Image.open()

im.show()

 

[展开全文]
成长的小白 · 2018-08-04 · 该任务已被删除 0

字符串操作

s = "hello world"

s.find("world")

>>>6 # 可查询world在字符串s中哪个位置

s[2:5]

>>>"llo" # 可截取第2到第4个字符(0开始)

列表操作

list = [1,2,3,4]

list.append("abc")  # 在list列表末尾追加abc字符串

list.remove("abc") # 在list列表中删除"abc"字符串(匹配字符值)

list.pop(1) # 删除该索引位置的元素,即删除第1位元素(0开始)

list[:2] # 输出第二位之前的所有元素

元组

一旦创建,不可更改

a = (1,2,3,4)

字典

d = {"name":wang,"age":18}

以键值对存储

d.keys() # 显示字典d的所有主键名

d.values() # 显示字典d的所有值

d["name"] #显示某个主键的值

del d['name'] # 删除某个键值对

d.items() #以列表方式显示所有键值对

类型转换

n = 1

s = str(n) # 将n转化为字符串类型

nn = int(s) # 将s转化为数值型

s = “www.baidu.com”

s.split(".") # 将s字符串以.为分割字符分割,会以列表形式输出

L = s.split(".") # L = ["www","baidu","com"]

".".join(L)

>>>“www.baidu.com”# 将列表L的元素用“.”来连接输出

 

 

 

[展开全文]
GG_1 · 2018-05-17 · 该任务已被删除 0

软件:pycharm  sublime

变量类型:数字 字符串 列表 元祖 字典

s.find()字符串查找函数

list.append()

list.remove()

list.pop()

dict.keys()

d.values()

del.d["age"]

d.items()

s.split() 字符串转换列表

".".join() 列表转换字符串

xrang()

文件操作:

open()

write()

readlines()

异常:

try:

except:

pass

except Exception e:

  print e

 

 

[展开全文]
成长的小白 · 2018-07-24 · 该任务已被删除 0

s=www.baidu.com

s.find("baidu") =4

切片

s[4:]  =baidu.com

s[4:10]  =baidu.

s[4:-3]  =baidu.

列表

增加 append()

删去 remove()

或用pop(i) i为列表中第几位

整数类型与字符串类型互换(非数字不可转成整数)

>>>n = 1
>>>s = str(n)
s = '1'
>>>m = int(s)
m = 1

字符串切割与合成

>>>s = "www.baidu.com"
>>>s.split(".")
{'www','baidu','com'}
>>>x = s.split(".")
>>>".".join(x)
'www.baidu.com'

文件

open()

close()

r 读

w 写

read()

write()

readlines()   返回一个列表

异常

try:

except:

 

 

 

 

 

 

 

[展开全文]
neuq_bingao · 2018-05-29 · 该任务已被删除 0

pip install bs4

r = requests.get(url)

doc = r.content

soup = BeautifulSoup(html_doc)

soup = BeautifulSoup(html_doc,'html.parser')

print soup.prettify() 打印出来源代码

soup.head 提取标签内容

soup.head.title

soup.find_all('p')  取出所有p标签

s = soup.find_all('p')

str(s)

soup.head.title.string or soup.title.string(标签唯一时候)   取出中间内容

for i in soup.find_all('a'):

print i['href']

soup.find_all(id='link2') 通过id定位语句

soup.find_all(class_='')

soup.find_all(id=True) 找出所有有id的节点

soup.find_all(text='elsie') 判断文本中有没有这个字符串

 

 

url = 'http://www.baidu.com'

r  = requests.get(url)

doc = r.content

soup = BeautifulSoup(doc)

 

 

 

 

 

 

[展开全文]
成长的小白 · 2018-07-27 · 该任务已被删除 0

#coding:utf-8
#auther:loop

import requests
import json
import loop_json

key = "baidu"

url = "https://api.github.com/search/code?q=%s" % key

TOKEN = '00e2b39028d493c56fc2737f7a9fa11011d02ef0'
headers = {"Authorization": "token %s" % TOKEN}
params = {"per_page": 10, "page": 0}
# = requests.get(url, headers=headers, params=params)

#d = r.json()

loop_json.abc()

print "test"

 

 

#coding:utf-8
import json
def abc(ddd):
    _dic = {"name":"loop", "age":"12"}

    s = json.dumps(_dic, indent=2)

    #print type(s)
    print "abc"

    #d = json.loads(s)

    #print d

if __name__ == "__main__":
    print "loop"

[展开全文]
neuq_bingao · 2018-06-27 · 该任务已被删除 0

授课教师

课程特色

视频(10)
下载资料(1)

学员动态

SDCIT_二九 开始学习 xunfeng
M影安 开始学习 requests_1
mumiao 开始学习 python_基础篇