-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: speed up the scrapper detection by domain (#37)
- Loading branch information
Victor Fernandes
authored
Feb 1, 2024
1 parent
ad85386
commit 8ce73f1
Showing
4 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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,27 @@ | ||
url: https://www.booking.com/searchresults* | ||
header: Booking.com search results | ||
listElementsQuery: '[data-testid="property-card"]' | ||
elementParser: | ||
- title: Title | ||
query: '[data-testid="title"]' | ||
type: text | ||
|
||
- title: Review score | ||
query: '[data-testid="review-score"] div:nth-child(1)' | ||
type: text | ||
|
||
- title: Distance | ||
query: '[data-testid="distance"]' | ||
type: text | ||
|
||
- title: Price w/ discounts | ||
query: '[data-testid="price-and-discounted-price"]' | ||
type: text | ||
|
||
- title: Offers | ||
query: '[data-testid="gallery-ribbon"]' | ||
type: text | ||
|
||
- title: Booking URL | ||
query: a | ||
type: clean-url |
This file contains 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,11 +1,27 @@ | ||
import { ScrapperOptions } from '../utils/chrome'; | ||
import { getDomainName, ScrapperOptions } from '../utils/chrome'; | ||
|
||
// @ts-ignore | ||
const data = import.meta.glob('./*.yml', { eager: true }); | ||
const scrappers: Array<ScrapperOptions> = []; | ||
const scrappers = new Map<string, Array<ScrapperOptions>>(); | ||
|
||
for (const scrapperPath in data) { | ||
scrappers.push(data[scrapperPath].default); | ||
const url = data[scrapperPath].default.url; | ||
let hostname = ''; | ||
|
||
if (Array.isArray(url)) { | ||
hostname = getDomainName(url[0]); | ||
} else { | ||
hostname = getDomainName(url); | ||
} | ||
|
||
if (hostname) { | ||
if (scrappers.has(hostname)) { | ||
const options = scrappers.get(hostname)!; | ||
scrappers.set(hostname, [...options, data[scrapperPath].default]); | ||
} else { | ||
scrappers.set(hostname, [data[scrapperPath].default]); | ||
} | ||
} | ||
} | ||
|
||
export default scrappers; |
This file contains 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