This repository was archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
fix all the errors #6
Open
stan2474
wants to merge
10
commits into
eg9y:master
Choose a base branch
from
stan2474:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
92d86ff
fix navigation timeout error
stan2474 8b62f5c
fix navigation errors
stan2474 2b1f351
update readme to show how to run
stan2474 36e62a6
should work now
stan2474 25c2289
target digital edition
stan2474 09e40f5
Update contants.ts
stan2474 766b185
making target digital scrapeable
stan2474 786ffbf
changing the original target to disc
stan2474 afb650b
done implementing digital and disc edition
stan2474 10674dc
adding the headless experimental feature
stan2474 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export const TARGET = 'Target' | ||
| export const TARGET = 'Target Disc Edition' | ||
| export const WALMART = 'Walmart' | ||
| export const PLAYSTATION_DIRECT = 'PlayStation Direct' | ||
| export const TARGET_DIGITAL = 'Target Digital Edition' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| import * as puppeteer from 'puppeteer' | ||
| import * as notifier from 'node-notifier' | ||
|
|
||
| export const scrapeTargetDigi = async (config: { [key: string]: string }) => { | ||
| const { | ||
| phoneNumber, | ||
| firstName, | ||
| lastName, | ||
| state, | ||
| city, | ||
| zipCode, | ||
| address, | ||
| creditCardNumber, | ||
| expirationMonth, | ||
| expirationYear, | ||
| cvv, | ||
| targetEmail, | ||
| targetPassword | ||
| } = config | ||
|
|
||
| if (!targetEmail || !targetPassword) { | ||
| throw new Error( | ||
| 'targetEmail and targetPassword settings not set in config.json' | ||
| ) | ||
| } | ||
|
|
||
| const browser = await puppeteer.launch({ | ||
| headless: false, | ||
| args: ['--window-size=1920,1080'], | ||
| defaultViewport: null | ||
| }) | ||
|
|
||
| try { | ||
| const page = await browser.newPage() | ||
| await page.setRequestInterception(true) | ||
| await page.setDefaultNavigationTimeout(0); | ||
|
|
||
| page.on('request', async req => { | ||
| if (req.resourceType() === 'image') { | ||
| await req.abort() | ||
| } else { | ||
| await req.continue() | ||
| } | ||
| }) | ||
|
|
||
| await page.goto('https://www.target.com') | ||
| const accountDropdown = await page.$('#account') | ||
| await accountDropdown.click() | ||
|
|
||
| await page.waitForTimeout(6000) | ||
| const signInButton = await page.$('#accountNav-signIn') | ||
| await signInButton.click() | ||
| await page.waitForTimeout(6000) | ||
| await page.type('#username', targetEmail) | ||
| await page.type('#password', targetPassword) | ||
| await page.keyboard.press('Enter') | ||
|
|
||
| await page.waitForTimeout(6000) | ||
| const isJoinRequest = await page.$('#circle-join-free') | ||
| if (isJoinRequest) { | ||
| console.log('join request exists') | ||
| const skipButton = await page.$('#circle-skip') | ||
| await skipButton.click() | ||
| } else { | ||
| console.log("join request doesn't exists") | ||
| } | ||
|
|
||
| await page.goto( | ||
| 'https://www.target.com/p/playstation-5-digital-edition-console/-/A-81114596' | ||
| ) | ||
| // await page.goto( | ||
| // 'https://www.target.com/p/dualsense-wireless-controller-for-playstation-5/-/A-81114477' | ||
| // ) | ||
|
|
||
| await page.waitForTimeout(4000) | ||
|
|
||
| while (true) { | ||
| try { | ||
| await page.waitForSelector('button[data-test="shipItButton"]', { | ||
| timeout: 10000 | ||
| }) | ||
| break | ||
| } catch (error) { | ||
| await page.reload() | ||
| } | ||
| } | ||
|
|
||
| const shipItButton = await page.$('button[data-test="shipItButton"]') | ||
| await shipItButton.click() | ||
| await page.waitForTimeout(4000) | ||
|
|
||
| const noCoverageButton = await page.$( | ||
| 'button[data-test="espModalContent-declineCoverageButton"]' | ||
| ) | ||
| await noCoverageButton.click() | ||
|
|
||
| await page.waitForTimeout(4000) | ||
| const addToCartModalViewCartCheckout = await page.$( | ||
| 'button[data-test="addToCartModalViewCartCheckout"]' | ||
| ) | ||
| await addToCartModalViewCartCheckout.click() | ||
|
|
||
| await page.waitForTimeout(6000) | ||
| const checkoutButton = await page.$('button[data-test="checkout-button"]') | ||
| await checkoutButton.click() | ||
|
|
||
| await page.waitForTimeout(6000) | ||
| const isCreditCardSavedAttemptOne = await page.$( | ||
| 'button[data-test="verify-card-button"]' | ||
| ) | ||
| if (isCreditCardSavedAttemptOne) { | ||
| await page.type('#creditCardInput-cardNumber', creditCardNumber) | ||
| // expiration date format: MM/YY e.g. 08/24 | ||
| await isCreditCardSavedAttemptOne.click() | ||
| await page.waitForTimeout(6000) | ||
| await page.type('#creditCardInput-cvv', cvv) | ||
| await page.keyboard.press('Enter') | ||
| } else { | ||
| // checkout page | ||
| const existingAddress = await page.$('div[data-test="address-0"]') | ||
| if (existingAddress) { | ||
| console.log('address exists') | ||
| await existingAddress.click() | ||
| const saveAndContinueButton = await page.$( | ||
| 'button[data-test="save-and-continue-button"]' | ||
| ) | ||
| await saveAndContinueButton.click() | ||
| } else { | ||
| console.log("address doesn't exists") | ||
| await page.type('#full_name', `${firstName} ${lastName}`) | ||
| await page.type('#address_line1', address) | ||
| await page.type('#zip_code', zipCode) | ||
| await page.type('#city', city) | ||
| await page.type('#mobile', phoneNumber) | ||
| await page.select('#state', state) | ||
| const saveAndContinueButton = await page.$( | ||
| 'button[data-test="saveButton"]' | ||
| ) | ||
| await saveAndContinueButton.click() | ||
| } | ||
| await page.waitForTimeout(6000) | ||
| await page.type('#creditCardInput-cardNumber', creditCardNumber) | ||
|
|
||
| const isCreditCardSaved = await page.$( | ||
| 'button[data-test="verify-card-button"]' | ||
| ) | ||
| if (!isCreditCardSaved) { | ||
| // expiration date format: MM/YY e.g. 08/24 | ||
| await page.type( | ||
| '#creditCardInput-expiration', | ||
| `${expirationMonth}/${expirationYear.slice(2, 4)}` | ||
| ) | ||
| await page.type('#creditCardInput-cvv', cvv) | ||
| await page.type('#creditCardInput-cardName', `${firstName} ${lastName}`) | ||
| const saveAndContinueButton = await page.$( | ||
| 'button[data-test="save-and-continue-button"]' | ||
| ) | ||
| await saveAndContinueButton.click() | ||
| } else { | ||
| await isCreditCardSaved.click() | ||
| await page.waitForTimeout(6000) | ||
| await page.type('#creditCardInput-cvv', cvv) | ||
| await page.keyboard.press('Enter') | ||
| } | ||
| } | ||
|
|
||
| notifier.notify({ | ||
| title: 'Target', | ||
| message: 'Ready to place order!', | ||
| sound: true | ||
| }) | ||
|
|
||
| // await page.waitForTimeout(4000) | ||
| // const placeOrderButton = await page.$( | ||
| // 'button[data-test="placeOrderButton"]' | ||
| // ) | ||
| // await placeOrderButton.click() | ||
| } catch (error) { | ||
| console.log(error) | ||
| } finally { | ||
| // await browser.close(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How different is this logic from the other target script? If it's mostly the URL, then I feel it's better to include another option in config.json to indicate digital,disc, or both and load the URL based on that. So,