I used jQuery and it seems to be working! I am using this: $("div#customerInfo table tr:nth-child(1) td:nth-child(7) img").attr("src")
Scrape image src attribute using pjscrape
-
06-03-2022 - |
Question
I'm having some difficulties with scraping the image source of an image. I tried the following:
_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img.attributes.src')
as well as
_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img[src]')
but nothing seems to be working. Is there a way to do this using getPattern
or maybe another way?
My code is below:
pjs.config({
// options: 'stdout', 'file' (set in config.logFile) or 'none'
log: 'stdout',
// options: 'json' or 'csv'
format: 'json',
// options: 'stdout' or 'file' (set in config.outFile)
//writer: 'stdout',
writer: 'file',
outFile: 'C:\\pjscrape\\pjscrape_out.txt'
});
pjs.addSuite({
url: 'http://localhost:8080/multivu.portal.htm',
scraper: function() {
return [
_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(2)'),
_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(4)'),
_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img.attributes.src')
];
}
});
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow