Class: Coupang

Inherits:
Object
  • Object
show all
Defined in:
lib/deltago.rb

Instance Method Summary collapse

Constructor Details

#initializeCoupang

Returns a new instance of Coupang.



1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
# File 'lib/deltago.rb', line 1381

def initialize
    @start_chrome = Thread.new do
        begin
            system('"'+"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"+'"'+" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/ChromeTEMP")
            system('"'+"C:/Program Files/Google/Chrome/Application/chrome.exe"+'"'+" https://naver.com/ --remote-debugging-port=9222 --user-data-dir=C:/ChromeTEMP")
        rescue => exception
            puts exception
        end
    end
    sleep(3)
    Selenium::WebDriver::Chrome.driver_path = './chromedriver.exe'
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_option("debuggerAddress", "127.0.0.1:9222")
    @driver = Selenium::WebDriver.for :chrome, options: options
    @driver.manage.window.maximize
    @wait = Selenium::WebDriver::Wait.new(:timeout => 5)
end

Instance Method Details

#get_product_data(name) ⇒ Object



1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'lib/deltago.rb', line 1429

def get_product_data(name)
    json = {
        'page' => {
            'pageNumber' => 0,
            'size' => 36
        },
        'deliveryTypes' => [],
        'filter' => name
    }

    http = HTTP.cookies(@cookie).post('https://partners.coupang.com/api/v1/search', :json => json)
    data = JSON.parse(http.to_s)['data']['products']
    puts data
    return data
end

#get_product_data2(where) ⇒ Object



1445
1446
1447
1448
1449
1450
1451
# File 'lib/deltago.rb', line 1445

def get_product_data2(where)
    http = HTTP.cookies(@cookie).get('https://partners.coupang.com/api/v1/discovery/'+where[0]+'?limit=20')
    puts http.to_s
    data = JSON.parse(http.to_s)['data']['products']
    puts data
    return data
end

#get_product_url(product_data) ⇒ Object



1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
# File 'lib/deltago.rb', line 1453

def get_product_url(product_data)
    json = {
        'product' => {
            'deliveryBadgeImage' => product_data['deliveryBadgeImage'],
            'discountRate' => nil,
            'image' => product_data['image'],
            'itemId' => product_data['itemId'],
            'originPrice' => product_data['originPrice'],
            'productId' => product_data['productId'],
            'salesPrice' => product_data['salesPrice'],
            'title' => product_data['title'],
            'type' => product_data['type'],
            'vendorItemId' => product_data['vendorItemId']
        }
    }
    begin
        http = http = HTTP.headers('x-token' => @cookie['AFATK']).cookies(@cookie).post('https://partners.coupang.com/api/v1/banner/iframe/url', :json => json)
        json = JSON.parse(http.to_s)
        puts json
        url = json['data']['shortUrl']
    rescue => exception
        puts exception
        puts '10초후 재시도 http error...'
        sleep(10)
        retry
    end
    puts url
    return url
end

#login(user_id, user_pw) ⇒ Object



1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/deltago.rb', line 1399

def (user_id,user_pw)
    @driver.get('https://partners.coupang.com/')
    begin
        sleep(3)
        element = @wait.until { @driver.find_element(:xpath, '//*[@id="app-header"]/div[2]/div/button[1]') }
        element.click

        e = @wait.until { @driver.find_element(:xpath, '//*[@id="login-email-input"]') }
        e.send_keys(user_id)
        @driver.find_element(:xpath, '//*[@id="login-password-input"]').send_keys(user_pw)
        sleep(1)
        #@driver.find_element(:xpath, '/html/body/div[1]/div/div/form/div[4]/label/span').click
        #sleep(1)
        @driver.find_element(:xpath, '/html/body/div[1]/div/div/form/div[5]/button').click
        sleep(5)

    rescue => exception
        puts exception
        puts 'logined'
    end
    sleep(2)
    @cookie = Hash.new
    @driver.manage.all_cookies.each do |cookie|
        @cookie[cookie[:name]] = cookie[:value]
    end
    puts @cookie
    sleep(2)
    @driver.close
end