def del_db_urls(table, urls): tuple_urls = tuple(urls) try: with ensure_conn().cursor() as cursor: sql = f"delete from {table} where href = %s" cursor.executemany(sql, tuple_urls) except pymysql.MySQLError as err: print(err)
def get_job_address(): address = [] try: with lagou.ensure_conn().cursor() as cursor: cursor.execute("select job_address from tb_data") for value in cursor.fetchall(): address.append(value[0][0:2]) except pymysql.MySQLError as err: print(err) return address
def get_db_urls(table, min, max): urls = [] try: with ensure_conn().cursor() as cursor: sql = f"select href from {table} limit %s, %s" cursor.execute(sql, (min, max)) for href in cursor.fetchall(): urls.append(href[0]) except pymysql.MySQLError as err: print(err) print(urls) return urls
def save_to_db(urls): try: with ensure_conn().cursor() as cursor: cursor.executemany("insert into tb_51(no, href) value(default, %s)", tuple(urls)) except pymysql.MySQLError as err: print(err)
def save_data(data): try: with ensure_conn().cursor() as cursor: cursor.execute("insert into tb_data(job_position, job_company, job_salary, job_address, job_info, job_advantage) values(%s, %s, %s, %s, %s, %s)", data[0]) except pymysql.MySQLError as err: print(err)