urllib requests 常用


import re
from bs4 import BeautifulSoup as bs
from urllib.request import quote
import pickle

import requests
import urllib.request
browser.set_page_load_timeout(30)
browser.set_script_timeout(30)
import time

# 格式化成2016-03-20 11:45:39形式
print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

# 格式化成Sat Mar 28 22:24:24 2016形式
print (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
  
# 将格式字符串转换为时间戳
a = "Sat Mar 28 22:24:24 2016"
print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
def cun():
    
    file = open('','wb')
    pickle.dump(lian,file)
    file.close()
    file = open('','wb')
    pickle.dump(chong,file)
    file.close()   


#字典合并函数
 def dic(dic1,dic2):
    for i in dic1:
        dic2[i]= dic1[i]

    return dic2

try:

    file = open('.pkl','rb')
    lian = pickle.load(file)
    file.close()
except:
    lian =[]
    file = open('.pkl','wb')
    pickle.dump(lian,file)
    file.close()
    file = open('.pkl','rb')
    lian = pickle.load(file)
def nwe_pkl(w):
    data ={}
    file = open(w,'wb')
    pickle.dump(data,file)
    file.close()
    file = open(w,'rb')
    data = pickle.load(file)
    file.close()
    return data

def cun_pkl(w):
    
    file = open(w,'rb')
    data = pickle.load(file)
    file.close()

def lian(url):

    headers ={}

    headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
    
    req = urllib.request.Request(url,headers = headers)

    html = urllib.request.urlopen(req)

    html = html.read()

    html = bs(html,'lxml')

    return html


    #data={}
    #data['']=''

    #data = urllib.parse.urlencode(data).encode('utf-8')
    #html = urllib.request.urlopen(req,data)



def lian2(url):
    
    headers ={}

    headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'

    html = requests.get(url,headers=headers)

    #data={}
    #data['']=''

    #html = requests.post(url,headers=headers,data=data)

    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值