Exemplo n.º 1
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        mysql = SQLUtil()
        username = request.form['username']

        from werkzeug.security import generate_password_hash
        password = generate_password_hash(request.form['password'])
        sql = "INSERT INTO user(name, password) VALUE ('%s','%s')" % (username,
                                                                      password)
        mysql.insertOne(sql)
        mysql.dispose()
        return render_template('login.html')
Exemplo n.º 2
0
def save_image(item, count):
    try:
        response = requests.get(item.get('image'))
        if response.status_code == 200:
            file_path = save_dir + '{0}.{1}'.format(str(count), 'jpg')
            if not os.path.exists(file_path):
                with open(file_path, 'wb') as f:
                    f.write(response.content)
            else:
                mysql = SQLUtil()
                sql = "INSERT INTO img (imgurl) VALUES ('%s')" % file_path
                mysql.insertOne(sql)
                print('下载到的目录', file_path)

    except requests.ConnectionError:
        print('下载图片失败')
Exemplo n.º 3
0
def parseOnePage(url):
    """

    :param url:
    :return:
    """
    header = {
        "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
    }
    ret = requests.get(url, headers=header)
    html = etree.HTML(ret.text)
    title = html.xpath('//div[*]/div[*]/div[*]/div[/*]/p[*]//text()')

    for i in range(len(title)):
        mysql = SQLUtil()
        sql = "INSERT INTO birthdayarticle(content) VALUES ('%s')" % (title[i])
        mysql.insertOne(sql)
        mysql.dispose()
Exemplo n.º 4
0
from Utils.SQLtool import SQLUtil

list = 'hahahhjjjjjj'
mysql = SQLUtil()
sql = "INSERT INTO img (imgurl) VALUE ('%s')" % list
print(sql, mysql.insertOne(sql))
mysql.insertOne(sql)