Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanning search instead of individual links. #2353

Closed
joeish opened this issue Apr 13, 2021 · 8 comments
Closed

Scanning search instead of individual links. #2353

joeish opened this issue Apr 13, 2021 · 8 comments

Comments

@joeish
Copy link

joeish commented Apr 13, 2021

Scan entire search instead of individual links, is this possible?

@AlexP11223
Copy link
Contributor

See linksBuilder (in the code, does not seem to be documented).

@joeish
Copy link
Author

joeish commented Apr 13, 2021

Do you know what would need to be changed in order to scan multiple items in search and display output instead of each product url?

@AlexP11223
Copy link
Contributor

@joeish
Copy link
Author

joeish commented Apr 14, 2021

import {Store} from './store';
import {getProductLinksBuilder} from './helpers/card';
export const CanadaComputers: Store = {
currency: '$',
labels: {
inStock: {
container: 'div[class="pi-prod-availability"]',
text: ['Online In Stock'],
},
maxPrice: {
container: '.h2-big > strong:nth-child(1)',
euroFormat: false,
},
},
links: [
{
brand: 'test:brand',
model: 'test:model',
series: 'test:series',
url:
'https://www.canadacomputers.com/product_info.php?item_id=167320&cPath=27_1046_365&language=en',
},
],
linksBuilder: {
builder: getProductLinksBuilder({
productsSelector: '.addCartSearch',
sitePrefix: 'https://www.canadacomputers.com',
titleSelector: '.text-center',
urlSelector: 'a[href]',
}),
urls: [

  {
    series: '3070',
    url:
      'https://www.canadacomputers.com/search/results_details.php?language=en&keywords=3070&cpath=43;557',
  },
  {
    series: '3090',
    url:
      'https://www.canadacomputers.com/search/results_details.php?language=en&keywords=3090&cpath=43;557',
  },
],

},
name: 'canadacomputers',
waitUntil: 'domcontentloaded',
};

Stuck running links builder, any ideas?

@AlexP11223
Copy link
Contributor

AlexP11223 commented Apr 17, 2021

It does not open for me.

Also format the code https://docs.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax#quoting-code

See how link builder is implemented, maybe you are using selectors wrong.

export function getProductLinksBuilder(options: LinksBuilderOptions) {
return (docElement: cheerio.Cheerio, series: Series): Link[] => {
const productElements = docElement.find(options.productsSelector);
const links: Link[] = [];
for (let i = 0; i < productElements.length; i++) {
const productElement = productElements.eq(i);
const titleElement = productElement.find(options.titleSelector).first();
const title = options.titleAttribute
? titleElement.attr()?.[options.titleAttribute]
: titleElement.text()?.replace(/\n/g, ' ').trim();
if (!title) {
continue;
}
let urlElement = titleElement;
if (options.urlSelector) {
urlElement = urlElement.find(options.urlSelector).first();
}
let url = urlElement.attr()?.href;
if (!url) {
continue;
}
if (isPartialUrlRegExp.exec(url)) {
url = options.sitePrefix + url;
}
const card = parseCard(title);
if (card) {
links.push({
brand: card.brand as any,
model: card.model,
series,
url,
});
} else {
logger.error(`Failed to parse card: ${title}`, {url});
}
}
return links;
};
}

Also you can add logging there to make debugging easier, such as logger.info(title) on line 30.

@AlexP11223
Copy link
Contributor

Also if the products in search are loaded via ajax, this may help: #2437

@github-actions
Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days

@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2021

This issue has been closed because it is stale. Reopen if necessary.

@github-actions github-actions bot closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants