This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
url = 'http://www.quanshuwang.com/book_113389.html' | |
r = requests.get(url=url) | |
r.encoding = 'gbk' | |
regex = re.compile(r'<a href="(.*?)" class="l mr11">') | |
novel_url = regex.findall(r.text) | |
print(novel_url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.db.models.base import ModelBase | |
def models_generator(db_table): | |
class CustomMetaClass(ModelBase): | |
def __new__(cls, name, bases, attrs): | |
model = super(CustomMetaClass, cls).__new__( | |
cls, name, bases, attrs) | |
model._meta.db_table = db_table | |
print(db_table) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base(object): | |
def __init__(self): | |
pass | |
def login(self, **kwargs): | |
# do something | |
pass | |
def logout(self, **kwargs): | |
# do something |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
from threading import Thread | |
def test(): | |
r = requests.get('http://zhuanlan.sina.com.cn/') | |
print(r.encoding) | |
soup = BeautifulSoup(r.content.decode('utf-8', 'ignore'), 'lxml') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
_sum = 5 # 这里的 _sum 对应了『给定数』 | |
_list = [1, 2, 3, 4, 5] # 这里就是输入的数据 对应了『一个数组』 | |
for i in range(len(_list)): | |
for num in combinations(_list, i + 1): # 这里循环是题设没有讲明几个数字相加,所以我用了从一个数字到所有数字相加 | |
if sum(num) == _sum: | |
print num # 这里就是结果了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinja2 import Environment | |
from hashlib import md5 | |
def ud_md5(file_name): | |
with open(file_name, 'rb') as f: | |
md_5 = md5() | |
md_5.update(f.read()) | |
return md_5.hexdigest() | |
def test(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def letter_sum(s): | |
return 0 if len(s) == 0 else get_number(s) | |
def test_number(s): | |
return 0 if int(s[0]) == 0 else 1 if int(s) in range(1, 27) else 0 | |
def get_number(s): | |
if len(s) == 1: |