from requests import Session
from proxy_randomizer import RegisteredProviders
import random
prox_list = []
s = Session()
rp = RegisteredProviders()
rp.parse_providers()
for x in range(20):
prox = str(rp.get_random_proxy()).partition(' ')[0]
for i in range(1): #тут, конечно смешно вышло, но иначе никак не получалось по 1 разу каждый прокси печатать
proxy = str({'http': 'http://' + prox}) # Получаем список Прокси
print(proxy)
#ЭТО СКОПИРОВАНО ИЗ КОНСОЛИ
# {'http': 'http://112.75.1.70:6666'}
# {'http': 'http://103.152.232.122:3125'}
# {'http': 'http://139.255.88.52:3128'}
# {'http': 'http://194.67.91.153:80'}
# {'http': 'http://112.75.1.71:6666'}
# {'http': 'http://103.141.108.122:9812'}
# {'http': 'http://112.75.1.98:6666'}
# {'http': 'http://219.78.228.211:80'}
# {'http': 'http://112.75.1.68:6666'}
# {'http': 'http://47.251.12.73:57114'}
# {'http': 'http://5.183.253.106:8085'}
# {'http': 'http://103.152.112.145:80'}
# {'http': 'http://185.129.199.209:29152'}
# {'http': 'http://45.148.125.236:8085'}
# {'http': 'http://112.75.1.101:6666'}
# {'http': 'http://49.207.36.81:80'}
# {'http': 'http://201.217.49.2:80'}
# {'http': 'http://43.224.10.26:6666'}
# {'http': 'http://194.5.207.151:3128'}
# {'http': 'http://103.164.113.211:8080'}
prox_list.append(proxy)
def get_session(randomize):
# создаем сессию для отправки HTTP запроса
# выбираем случайным образом один из адресов
proxies = random.choice(prox_list)
s.proxies = proxies
return s
for i in range(5):
r = get_session(prox_list)
try:
print('Request page with IP:', r.get('http://icanhazip.com', timeout=1.5).text.strip())
except TimeoutError as e:
continue
Request page with IP: 92.xxxxxxxx
Request page with IP: 92.xxxxxxxx
Request page with IP: 92.xxxxxxxx
Request page with IP: 92.xxxxxxxx
Request page with IP: 92.xxxxxxxx
https://www.newegg.com/p/2BH-004K-000J4?recaptcha=pass
recaptcha=pass
import csv
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from tqdm import tqdm
from requests import Session
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
s = Session()
options = webdriver.ChromeOptions()
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(executable_path=r'/home/anatolii/PycharmProjects/pythonProject/chromedriver', options=options)
wait = WebDriverWait(driver, 10)
with open('useful_links1.txt', 'r') as f:
lines = [line.strip() for line in f.readlines()]
models = []
for line in lines:
driver.get(line)
sleep(30)
name = wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'product-title'))).__getattribute__('text')
price_strong = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#app > div.page-content > div > div > div '
'> '
'div.row-side > div.product-buy-box > '
'div.product-pane > div.product-price > ul '
'> '
'li.price-current > strong'))) \
.__getattribute__('text')
price_sup = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#app > div.page-content > div > div > div > '
'div.row-side > div.product-buy-box > '
'div.product-pane > div.product-price > ul > '
'li.price-current > sup'))).__getattribute__(
'text')
price = price_strong + price_sup
try:
specific = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#app > div.page-content > div > div > div '
'> div.row-body > '
'div.product-main.display-flex > '
'div.product-wrap > div.product-bullets > '
'ul'))).__getattribute__('text')
# except NoSuchElementException as ex:
# pass
except TimeoutException as ex:
pass
img = wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'product-view-img-original')))
src = img.get_attribute('src')
try:
p = s.get(src)
try:
with open(f'/home/anatolii/PycharmProjects/pythonProject/selen_img/{name}.jpg', 'wb') as file:
file.write(p.content)
except FileNotFoundError:
pass
pass
except AttributeError:
pass
photo_path = f'/home/anatolii/PycharmProjects/pythonProject/selen_img/{name}.jpg'
model = {
'name': name,
'price': price,
'specific': specific,
'photo_path': photo_path,
}
models.append(model)
with open('companys2.csv', 'w', newline='') as file:
writer = csv.writer(file, delimiter=',', lineterminator='\r')
writer.writerow(['Name', 'Price', 'Specific', 'Photo_path'])
for model in tqdm(models):
writer.writerow(
[model['name'], model['price'], model['specific'], model['photo_path']])
sleep(30)
driver.quit()
driver.close()
NameError: name 'specific' is not defined