mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
sr2
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
//#include "dz_func.h"
|
|
||||||
|
|
||||||
void bin_search(struct st tmp[], int n){
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -0,0 +1,68 @@
|
|||||||
|
#include "funcHeader.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
|
People* professions1 = malloc(sizeof(People) * COUN);
|
||||||
|
People* professions2 = malloc(sizeof(People) * COUN);
|
||||||
|
|
||||||
|
if (professions1 == NULL || professions2 == NULL) {
|
||||||
|
printf("Mesta net\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
st_rand(professions1, COUN);
|
||||||
|
st_rand(professions2, COUN);
|
||||||
|
|
||||||
|
printf("Perviy massiv:\n");
|
||||||
|
print_struc(professions1, COUN);
|
||||||
|
printf("\nVtoroi massiv:\n");
|
||||||
|
print_struc(professions2, COUN);
|
||||||
|
|
||||||
|
sort_sel(professions1, COUN);
|
||||||
|
sort_sel(professions2, COUN);
|
||||||
|
|
||||||
|
printf("\nPerviy massiv posle sort:\n");
|
||||||
|
print_struc(professions1, COUN);
|
||||||
|
printf("\nVtoroi massiv posle sort:\n");
|
||||||
|
print_struc(professions2, COUN);
|
||||||
|
|
||||||
|
People* ans = binSearch(professions1, COUN, 15);
|
||||||
|
|
||||||
|
if (ans == NULL)
|
||||||
|
printf("\nPeoples net\n");
|
||||||
|
else
|
||||||
|
printf("\nLength: %2d; name: %s\n", ans->count, ans->name);
|
||||||
|
|
||||||
|
printf("\nElement in perviy massiv: ");
|
||||||
|
pst(professions1, COUN, (int)(COUN * 0.7));
|
||||||
|
printf("Element in vtoroi massiv: ");
|
||||||
|
pst(professions2, COUN, (int)(COUN * 0.3));
|
||||||
|
|
||||||
|
printf("\nNumber of para : %d\n", find_para(professions1, COUN, professions2, COUN));
|
||||||
|
|
||||||
|
st_fprintf(professions1, COUN, "professions.txt", "w");
|
||||||
|
st_fprintf(professions2, COUN, "professions.txt", "a");
|
||||||
|
|
||||||
|
int line_number = lines_numf("professions.txt");
|
||||||
|
printf("\nNumber of lines in professions.txt is %d\n", line_number);
|
||||||
|
|
||||||
|
People* professions3 = malloc(sizeof(People) * line_number);
|
||||||
|
|
||||||
|
if (professions3 == NULL) {
|
||||||
|
printf("Mesta net\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
st_fscanf(professions3, line_number, "professions.txt");
|
||||||
|
sort_sel(professions3, line_number);
|
||||||
|
|
||||||
|
Sleep(50000);
|
||||||
|
|
||||||
|
printf("\nTTretiy massiv is:\n");
|
||||||
|
print_struc(professions3, line_number);
|
||||||
|
free(professions1);
|
||||||
|
free(professions2);
|
||||||
|
free(professions3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#define COUN 4
|
||||||
|
#define LEN 8
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct People {
|
||||||
|
int count;
|
||||||
|
char name[LEN];
|
||||||
|
} People;
|
||||||
|
|
||||||
|
void print_struc(People professions[], int n);
|
||||||
|
void sort_sel(People professions[], int n);
|
||||||
|
void st_rand(People professions[], int n);
|
||||||
|
People* binSearch(People professions[], int n, int k);
|
||||||
|
void pst(People professions[], int s, int n);
|
||||||
|
int find_para(People t1[], int n1, People t2[], int n2);
|
||||||
|
void st_fprintf(People professions[], int n, char path[], char access[]);
|
||||||
|
int lines_numf(char path[]);
|
||||||
|
void st_fscanf(People t[], int n, char path[]);
|
||||||
|
void swap(People* t1, People* t2);
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
#include "funcHeader.h"
|
||||||
|
|
||||||
|
void print_struc(People professions[], int n) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
printf("count: %3d; name: %s\n", professions[i].count, professions[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort_sel(People professions[], int n) {
|
||||||
|
int i, j;
|
||||||
|
for (i = 0; i < n - 1; i++) {
|
||||||
|
for (j = i + 1; j < n; j++) {
|
||||||
|
if (professions[j].count < professions[i].count)
|
||||||
|
swap(professions + i, professions + j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void st_rand(People professions[], int n) {
|
||||||
|
int i, j;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
professions[i].count = rand() % 3 + 1;
|
||||||
|
for (j = 0; j < LEN - 1; j++)
|
||||||
|
professions[i].name[j] = 'a' + rand() % 25;
|
||||||
|
professions[i].name[j + 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
People* binSearch(People professions[], int n, int k) {
|
||||||
|
People* ans = NULL;
|
||||||
|
int right = 0, left = n - 1;
|
||||||
|
|
||||||
|
while (right <= left) {
|
||||||
|
int mid = (left + right) / 2;
|
||||||
|
|
||||||
|
if (professions[mid].count == k) {
|
||||||
|
ans = &professions[mid];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
right = (professions[mid].count < k) ? mid + 1: right;
|
||||||
|
left = (professions[mid].count > k) ? mid - 1: left;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pst(People professions[], int s, int n) {
|
||||||
|
if (n >= s) {
|
||||||
|
printf("Out of range\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("count: %2d; name: %s\n", professions[n].count, professions[n].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int find_para(People t1[], int n1, People t2[], int n2) {
|
||||||
|
int ans = 0, i;
|
||||||
|
for (i = 0; i < n1; i++) {
|
||||||
|
People* tans = binSearch(t2, n2, t1[i].count);
|
||||||
|
if (tans == NULL) continue;
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void st_fprintf(People professions[], int n, char path[], char access[]) {
|
||||||
|
int i;
|
||||||
|
FILE* f = fopen(path, access);
|
||||||
|
if (f == NULL) {
|
||||||
|
printf("Could not open file %s\n", path);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
fprintf(f, "%d %s\n", professions[i].count, professions[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lines_numf(char path[]) {
|
||||||
|
int ans = 0;
|
||||||
|
char c;
|
||||||
|
FILE* f = fopen(path, "r");
|
||||||
|
if (f == NULL) {
|
||||||
|
printf("Faila %s net...\n", path);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((c = fgetc(f)) != EOF) {
|
||||||
|
if (c == '\n') ans++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
void st_fscanf(People t[], int n, char path[]) {
|
||||||
|
int i;
|
||||||
|
FILE* f = fopen(path, "r");
|
||||||
|
if (f == NULL) {
|
||||||
|
printf("Faila %s net...\n", path);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
fscanf(f, "%d %s\n", &t[i].count, t[i].name);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap(People* t1, People* t2) {
|
||||||
|
People* tmp = malloc(sizeof(People));
|
||||||
|
|
||||||
|
if (tmp == NULL) {
|
||||||
|
printf("could not malloc\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(tmp, t1, sizeof(People));
|
||||||
|
memcpy(t1, t2, sizeof(People));
|
||||||
|
memcpy(t2, tmp, sizeof(People));
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
1 pkaeoew
|
||||||
|
1 ujqrkpqP
|
||||||
|
2 nllvevc=
|
||||||
|
2 wrqqkwf(
|
||||||
|
1 krxtlgme
|
||||||
|
1 srgyisre
|
||||||
|
3 tiflqbd(
|
||||||
|
3 opukfbci
|
||||||
Binary file not shown.
@@ -14,7 +14,7 @@ creat_qwery = """ create table Parser
|
|||||||
cursor.execute(creat_qwery)
|
cursor.execute(creat_qwery)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
driver = Service('D:\teach\Prog\chromedriver.exe')
|
driver = Service('D:\\teach\Prog\chromedriver.exe')
|
||||||
browser = webdriver.Chrome(service=driver)
|
browser = webdriver.Chrome(service=driver)
|
||||||
browser.get('https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/')
|
browser.get('https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/')
|
||||||
html_code = browser.page_source
|
html_code = browser.page_source
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.chrome.service import Service
|
||||||
|
import psycopg2
|
||||||
|
import wget
|
||||||
|
|
||||||
|
# connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||||
|
# cursor = connection.cursor()
|
||||||
|
|
||||||
|
s = Service('D:\Games\data\chromedriver.exe')
|
||||||
|
browser = webdriver.Chrome(service=s)
|
||||||
|
browser.get('https://www.volkswagen.ru/polo/')
|
||||||
|
html_text = browser.page_source
|
||||||
|
soup = BeautifulSoup(html_text, 'lxml')
|
||||||
|
|
||||||
|
# creat_table = """ create table Cars_volks
|
||||||
|
# (id serial primary key, car_name varchar(20),
|
||||||
|
# price varchar(15), adress varchar(40),
|
||||||
|
# scr varchar(100)) """
|
||||||
|
#cursor.execute(creat_table)
|
||||||
|
# connection.commit()
|
||||||
|
|
||||||
|
car_names = soup.find_all('div', class_='avn001-2_name')
|
||||||
|
prices = soup.find_all('div', class_='avn001-2_price-container')
|
||||||
|
adresses = soup.find_all('div', class_='avn001-2_dealer-link__text')
|
||||||
|
pictures = soup.find_all('div', class_='avn001-2_image image__container')
|
||||||
|
|
||||||
|
#for car_name, adress, price in zip(car_names, adresses, prices):
|
||||||
|
# print(f"Название машины:{car_name.text} | Адрес диллера: {adress.text} | Цена: {price.text} рублей")
|
||||||
|
|
||||||
|
for i in range(4):
|
||||||
|
url = pictures[i].find('img').attrs['src']
|
||||||
|
filename = f"Programming\\other\\img\\img{i}.jpg"
|
||||||
|
print(filename)
|
||||||
|
wget.download(url, filename)
|
||||||
|
|
||||||
|
# insert_qwery = f"""INSERT INTO public.Cars_volks(car_name, price, adress, scr)
|
||||||
|
# VALUES ('{car_names[i].text}', '{prices[i].text}', '{adresses[i].text}', '{filename}')""";
|
||||||
|
# cursor.execute(insert_qwery)
|
||||||
|
# connection.commit()
|
||||||
|
|
||||||
|
# cursor.close()
|
||||||
|
# connection.close()
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Reference in New Issue
Block a user