poshmark/poshare.py
2020-05-25 18:36:44 -07:00

89 lines
4.5 KiB
Python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import random
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup as b
import time
from selenium.common.exceptions import ElementClickInterceptedException
browser = webdriver.Firefox(executable_path="C:/Users/unknown/Desktop/projects/geckodriver")
wait = WebDriverWait(browser, 30)
browser.get('https://poshmark.com/login')
usename = browser.find_element_by_id('login_form_username_email')
usename.send_keys('SpeanutButter')
psw = browser.find_element_by_id('login_form_password')
psw.send_keys('***REMOVED***')
psw.submit()
input('press "enter" to continue')
wait.until(EC.presence_of_element_located((By.XPATH, "//title[text()='Feed - Poshmark']")))
browser.get('https://poshmark.com/closet/speanutbutter?department=Women&sort_by=price_desc')
input('press "enter" to continue')
html = browser.page_source
soup = b(html)
elm = browser.find_element_by_tag_name('html')
while not soup.find('i', text = "Not for Sale"):
elm.send_keys(Keys.END)
html = browser.page_source
soup = b(html)
list_titles = soup.find_all('a',{'class':'title'})
active_listings = soup.find_all('i', {'class':"icon share-gray"})
print(len(active_listings))
container = browser.find_elements_by_xpath("//div[@id='tiles-con']/div")
i = -1
share_to = input('share to followers (F) or share to party (P)?: ')
for divs in container:
i += 1
wait.until(EC.presence_of_element_located((By.XPATH, ".//i[@class = 'icon share-gray']")))
try:
if divs.find_element_by_xpath(".//i[@class = 'icon inventory-tag not-for-sale-tag']"):
pass
except NoSuchElementException:
try:
if divs.find_element_by_xpath(".//i[@class = 'icon inventory-tag sold-tag']"):
pass
except NoSuchElementException:
share = divs.find_element_by_xpath(".//i[@class = 'icon share-gray']")
time.sleep(random.uniform(.6,1.2))
try:
share.click()
if soup.find('input', id = "recaptcha-token"):
input('Finish recapcha and press "enter" to continue')
if soup.find('span', text = "I'm not a robot"):
input('Finish recapcha and press "enter" to continue')
if share_to == 'F':
wait.until(EC.presence_of_element_located((By.XPATH, "//span[text()='To My Followers']")))
share = browser.find_element_by_xpath("//span[text()='To My Followers']")
time.sleep(random.uniform(.6,1.2))
share.click()
if soup.find('input', id = "recaptcha-token"):
input('Finish recapcha and press "enter" to continue')
print(i)
if soup.find('span', text = "I'm not a robot"):
input('Finish recapcha and press "enter" to continue')
title = list_titles[i].get_text()
print(title)
if share_to == 'P':
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Happening Now')]")))
share = browser.find_element_by_xpath("//*[contains(text(), 'Happening Now')]")
time.sleep(random.uniform(.6,1.2))
share.click()
if soup.find('input', id = "recaptcha-token"):
input('Finish recapcha and press "enter" to continue')
if soup.find('span', text = "I'm not a robot"):
input('Finish recapcha and press "enter" to continue')
print(i)
title = list_titles[i].get_text()
print(title)
except ElementClickInterceptedException:
pass
'''If poshmark lets you browser.get any page then you should skip the pagination loading to load all the pages and then just go through each page and share that way. It wouldn't be such a time consuming process'''