|
@@ -123,13 +123,14 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
});
|
|
});
|
|
}, 250);
|
|
}, 250);
|
|
}))
|
|
}))
|
|
- .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article/*/*/*/*/*[@role="group"]]', {timeout: getTimeout()}))
|
|
|
|
|
|
+ // find main tweet
|
|
|
|
+ .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//*[@data-testid]//time)]]', {timeout: getTimeout()}))
|
|
// toggle visibility of sensitive tweets
|
|
// toggle visibility of sensitive tweets
|
|
.then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
|
|
.then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
|
|
.then(sensitiveToggles => {
|
|
.then(sensitiveToggles => {
|
|
const count = sensitiveToggles.length;
|
|
const count = sensitiveToggles.length;
|
|
if (count) logger.info(`found ${count} sensitive ${count === 1 ? 'tweet' : 'tweets'} on page, uncollapsing...`);
|
|
if (count) logger.info(`found ${count} sensitive ${count === 1 ? 'tweet' : 'tweets'} on page, uncollapsing...`);
|
|
- return Promise.all(sensitiveToggles.map(toggle => toggle.click()));
|
|
|
|
|
|
+ return chainPromises(sensitiveToggles.filter(toggle => toggle.isVisible()).map(toggle => () => toggle.click()));
|
|
})
|
|
})
|
|
.then(() => handle)
|
|
.then(() => handle)
|
|
)
|
|
)
|
|
@@ -153,10 +154,11 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
}
|
|
}
|
|
} catch {/* handle errors like none-found cases */}
|
|
} catch {/* handle errors like none-found cases */}
|
|
document.documentElement.scrollTop = 0;
|
|
document.documentElement.scrollTop = 0;
|
|
- });
|
|
|
|
|
|
+ }).then(() => handle);
|
|
})
|
|
})
|
|
- .then(() => page.evaluate(() => {
|
|
|
|
- const cardImg = document.querySelector('div[data-testid^="card.layout"][data-testid$=".media"] img');
|
|
|
|
|
|
+ // scrape card image from main tweet
|
|
|
|
+ .then(handle => handle.evaluate(div => {
|
|
|
|
+ const cardImg = div.querySelector('div[data-testid^="card.layout"][data-testid$=".media"] img');
|
|
if (typeof cardImg?.getAttribute('src') === 'string') {
|
|
if (typeof cardImg?.getAttribute('src') === 'string') {
|
|
const match = /^(.*\/card_img\/(\d+)\/.+\?format=.*)&name=/.exec(cardImg?.getAttribute('src'));
|
|
const match = /^(.*\/card_img\/(\d+)\/.+\?format=.*)&name=/.exec(cardImg?.getAttribute('src'));
|
|
if (match) {
|
|
if (match) {
|