Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import pandas as pd
- import requests
- from bs4 import BeautifulSoup as bs
- import cv2
- import numpy as np
- def readb64(uri): # Функция чтобы читать png:base64 изображения
- encoded_data = uri.split(',')[1]
- nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8)
- img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
- return img
- main_url = "http://autosale2022.task-sss.krasilnikov.spb.ru"
- url = main_url + "/ads/6ed459ea169d96c38c7167d4cf471013"
- response = requests.get(url)
- # print(response.text)
- task = [] # Массив для строк
- soup = bs(response.text,'html.parser')
- i = 0
- for link in soup.find_all('a'):
- i+=1
- print('Check ' + str(i) + ' car')
- car_url = main_url+link['href']
- response = requests.get(car_url)
- car_soup = bs(response.text,'html.parser')
- id = car_soup.find('td', string = "id").find_next_sibling().get_text()
- name = car_soup.find('td', string = "name").find_next_sibling().get_text()
- acceleration = car_soup.find('td', string = "acceleration").find_next_sibling().get_text()
- year = car_soup.find('td', string = "year").find_next_sibling().get_text()
- origin = car_soup.find('td', string = "origin").find_next_sibling().get_text()
- displacement = car_soup.find('td', string = "displacement").find_next_sibling().get_text() # Не работает
- # print(id,name,acceleration)
- # Манипуляции с QR кодом
- img_url = car_soup.find('td', string = "weight").find_next_sibling().find('img')['src']
- img = readb64(img_url)
- detector = cv2.QRCodeDetector()
- weight = detector.detectAndDecode(img)[0]
- task.append((id,name,year,acceleration,origin,weight))
- # task1_temp.append(name)
- # task1_temp.append(year)
- # task1_temp.append(acceleration)
- # task1_temp.append(origin)
- data_task1 = pd.DataFrame(task)
- print(data_task1)
Add Comment
Please, Sign In to add comment