Created
March 6, 2025 00:15
-
-
Save wall-e-08/13ee4e52d6267d7358b58114f06b7f0b to your computer and use it in GitHub Desktop.
test webscrap by typescript
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
| import {Builder, By, until, Browser, Key, WebDriver, WebElement, ThenableWebDriver} from 'selenium-webdriver'; | |
| import chrome, {Options} from 'selenium-webdriver/chrome'; | |
| const screen: {width: number, height: number} = { | |
| width: 640, | |
| height: 480 | |
| }; | |
| /*let driver = new Builder() | |
| .forBrowser('chrome') | |
| .setChromeOptions(<Options>new chrome.Options() | |
| .addArguments('--headless=new') | |
| // .windowSize(screen) | |
| ) | |
| .build();*/ | |
| let driver = new Builder() | |
| .forBrowser('chrome') | |
| .setChromeOptions(<Options>new chrome.Options() | |
| // .addArguments('--headless=new', '--disable-gpu') | |
| .windowSize(screen) | |
| ) | |
| .build(); | |
| (async function amazonJobScrapper(): Promise<void> { | |
| // let driver: WebDriver = await new Builder().forBrowser(Browser.CHROME).build() | |
| try { | |
| console.log("loading..") | |
| await driver.get('https://www.jobsatamazon.co.uk/app#/jobSearch?query=&locale=en-GB') | |
| // await driver.findElement(By.css('#pageRouter .colContainerTop')).sendKeys('webdriver', Key.RETURN) | |
| // await driver.wait(until.titleIs('webdriver - Google Search'), 1000) | |
| console.log("waiting for..") | |
| // Wait for job listings to load | |
| await driver.wait(until.elementsLocated(By.css('#pageRouter .colContainerTop')), 10000); | |
| // Extract job listings | |
| let jobElements = await driver.findElements(By.css('#pageRouter .colContainerTop')); | |
| let jobs = []; | |
| for (let jobElement of jobElements) { | |
| let _gg = await jobElement.getText(); | |
| console.log(`huh? : ${_gg}, --`) | |
| let jobTitleElement = await jobElement.findElement( | |
| // By.css('div[data-test-component="StencilText"] strong') | |
| By.css('.jobDetailText strong') | |
| ); | |
| let jobTitle: string = await jobTitleElement.getText(); | |
| console.log(`Job title: ${jobTitle}`); | |
| } | |
| // for (let jobElement of jobElements) { | |
| // let title = await jobElement.findElement(By.css('.job-title')).getText(); | |
| // let location = await jobElement.findElement(By.css('.location')).getText(); | |
| // let link = await jobElement.findElement(By.css('a')).getAttribute('href'); | |
| // | |
| // jobs.push({ title, location, link }); | |
| // } | |
| // console.log(jobElements); | |
| } finally { | |
| await driver.quit() | |
| } | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment