浏览代码

fix finding main tweet

Mike L 3 年之前
父节点
当前提交
def84a5cf8
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 1 1
      dist/webshot.js
  2. 5 2
      src/webshot.ts

+ 1 - 1
dist/webshot.js

@@ -101,7 +101,7 @@ class Webshot extends CallableInstance {
                             });
                         }, 250);
                     }))
-                        .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//*[@data-testid]//time)]]', { timeout: getTimeout() }))
+                        .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//time[not(ancestor::div[@aria-labelledby])])]]', { timeout: getTimeout() }))
                         .then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
                         .then(sensitiveToggles => {
                         const count = sensitiveToggles.length;

+ 5 - 2
src/webshot.ts

@@ -129,7 +129,10 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
               }, 250);
             }))
             // find main tweet
-            .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//*[@data-testid]//time)]]', {timeout: getTimeout()}))
+            .then(() => page.waitForSelector(
+              'xpath=//section/*/*/div[.//article[not(.//time[not(ancestor::div[@aria-labelledby])])]]',
+              {timeout: getTimeout()}
+            ))
             // toggle visibility of sensitive tweets
             .then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
               .then(sensitiveToggles => {
@@ -146,7 +149,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
               logger.warn(`navigation timed out at ${getTimerTime()} seconds`);
               return null;
             })
-            // scroll to last tweet by owner in thread, if any, or top of thread
+            // scroll to 2nd last tweet by owner in thread, if any, or top of thread
             .then((handle: puppeteer.ElementHandle<HTMLDivElement>) => {
               if (handle === null) throw new puppeteer.errors.TimeoutError();
               return handle.evaluate(div => {