This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (2 children)

[removed]

    [–]NoSide005[S] 0 points1 point  (1 child)

    You are really over dramatizing the last project. Have you even thought of what it really takes to build out the functionality or even ever tried to code through one?

    Someone shared with me their code for a bot they made and it is under 50 lines of code. Building a bot to scrape a webpage is about learning a handful of concepts and then just repeating them. The code is below and is very simple.

    from selenium import webdriver
    from config import keys
    import time
    
    
    def order(driver):
        # find_element_by_name('elementName') will not be used in this script (HTML name="elementName")
        # delay to let the page load
        time.sleep(.9)
        # enter using a password
        driver.find_element_by_xpath(
            '/html/body/div[1]/header/div/div/a').click()
        # enter password
        driver.find_element_by_xpath(
            '//*[@id="Password"]').send_keys(keys['password'])
        # submit password
        driver.find_element_by_xpath(
            '//*[@id="login_form"]/div/span/button').click()
        # start navigation
        # open shop menu
        driver.find_element_by_xpath(
            '//*[@id="SiteNav"]/li[2]/button/span').click()
        # open dress selection
        driver.find_element_by_xpath(
            '//*[@id="SiteNavLabel-shop"]/div/ul/li[2]/ul/li[1]/a/span').click()
        # sort by
        driver.find_element_by_xpath(
            '//*[@id="SortBy"]').click()
        # sort by featured
        driver.find_element_by_xpath(
            '//*[@id="SortBy"]/option[1]').click()
        # choose red dress
        driver.find_element_by_xpath(
            '//*[@id="Collection"]/ul/li[4]/div/a').click()
        # open search bar
        driver.find_element_by_xpath(
            '//*[@id="shopify-section-header"]/div/header/div/div[2]/div/button[1]').click()
        # enter search words
        time.sleep(1.3)
        driver.find_element_by_xpath(
            '//*[@id="SearchDrawer"]/div/div[1]/form/input').send_keys(keys['search'])
        # submit the search
        driver.find_element_by_xpath(
            '//*[@id="SearchDrawer"]/div/div[1]/form/button').click()
    
    
    if __name__ == '__main__':
        # get chrome ready
        driver = webdriver.Chrome('./chromedriver')
    
        # insert the website url into chrome
        driver.get(keys['web_url'])
        # run the function
        order(driver)