instauto 9.1.6 → 9.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/package.json +1 -1
  3. package/src/index.js +34 -15
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ![](logo.png)
2
2
 
3
+ [![Discord](https://img.shields.io/discord/986052713425027072)](https://discord.gg/Rh3KT9zyhj) [![PayPal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/mifino/usd)
4
+
3
5
  instauto is an Instagram automation/bot library written in modern, clean javascript using Google's Puppeteer. Goal is to be very easy to set up, use, and extend, and obey instagram's limits. Heavily inspired by [InstaPy](https://github.com/timgrossmann/InstaPy), but I thought it was way too heavy and hard to setup.
4
6
 
5
7
  **NEW! 🎉**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instauto",
3
- "version": "9.1.6",
3
+ "version": "9.1.9",
4
4
  "description": "Instagram automation library written in Node.js",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -170,11 +170,14 @@ const Instauto = async (db, browser, options) => {
170
170
  return new Date().getTime() - followedUserEntry.time < dontUnfollowUntilTimeElapsed;
171
171
  }
172
172
 
173
+ // See https://github.com/mifi/SimpleInstaBot/issues/140#issuecomment-1149105387
174
+ const gotoUrl = async (url) => page.goto(url, { waitUntil: ['load', 'domcontentloaded', 'networkidle0'] });
175
+
173
176
  async function gotoWithRetry(url) {
174
177
  const maxAttempts = 3;
175
178
  for (let attempt = 0; ; attempt += 1) {
176
179
  logger.log(`Goto ${url}`);
177
- const response = await page.goto(url);
180
+ const response = await gotoUrl(url);
178
181
  await sleep(2000);
179
182
  const status = response.status();
180
183
 
@@ -312,17 +315,23 @@ const Instauto = async (db, browser, options) => {
312
315
  }
313
316
 
314
317
  async function findUnfollowButton() {
315
- const elementHandles = await page.$x("//header//button[text()='Following']");
318
+ let button = await findButtonWithText('Following');
319
+ if (button) return button;
320
+
321
+ button = await findButtonWithText('Requested');
322
+ if (button) return button;
323
+
324
+ let elementHandles = await page.$x("//header//button[*//span[@aria-label='Following']]");
316
325
  if (elementHandles.length > 0) return elementHandles[0];
317
326
 
318
- const elementHandles2 = await page.$x("//header//button[text()='Requested']");
319
- if (elementHandles2.length > 0) return elementHandles2[0];
327
+ elementHandles = await page.$x("//header//button[*//span[@aria-label='Requested']]");
328
+ if (elementHandles.length > 0) return elementHandles[0];
320
329
 
321
- const elementHandles3 = await page.$x("//header//button[*//span[@aria-label='Following']]");
322
- if (elementHandles3.length > 0) return elementHandles3[0];
330
+ elementHandles = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
331
+ if (elementHandles.length > 0) return elementHandles[0];
323
332
 
324
- const elementHandles4 = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Following']]");
325
- if (elementHandles4.length > 0) return elementHandles4[0];
333
+ elementHandles = await page.$x("//header//button[*//*[name()='svg'][@aria-label='Requested']]");
334
+ if (elementHandles.length > 0) return elementHandles[0];
326
335
 
327
336
  return undefined;
328
337
  }
@@ -795,7 +804,7 @@ const Instauto = async (db, browser, options) => {
795
804
 
796
805
  if (enableCookies) await tryLoadCookies();
797
806
 
798
- const goHome = async () => page.goto(`${instagramBaseUrl}/?hl=en`);
807
+ const goHome = async () => gotoUrl(`${instagramBaseUrl}/?hl=en`);
799
808
 
800
809
  // https://github.com/mifi/SimpleInstaBot/issues/28
801
810
  async function setLang(short, long, assumeLoggedIn = false) {
@@ -807,7 +816,7 @@ const Instauto = async (db, browser, options) => {
807
816
  // when logged in, we need to go to account in order to be able to check/set language
808
817
  // (need to see the footer)
809
818
  if (assumeLoggedIn) {
810
- await page.goto(`${instagramBaseUrl}/accounts/edit/`);
819
+ await gotoUrl(`${instagramBaseUrl}/accounts/edit/`);
811
820
  } else {
812
821
  await goHome();
813
822
  }
@@ -872,6 +881,19 @@ const Instauto = async (db, browser, options) => {
872
881
  }
873
882
  }
874
883
 
884
+ async function tryClickLogin() {
885
+ async function tryClickButton(xpath) {
886
+ const btn = (await page.$x(xpath))[0];
887
+ if (!btn) return false;
888
+ await btn.click();
889
+ return true;
890
+ }
891
+
892
+ if (await tryClickButton("//button[.//text() = 'Log In']")) return true;
893
+ if (await tryClickButton("//button[.//text() = 'Log in']")) return true; // https://github.com/mifi/instauto/pull/110 https://github.com/mifi/instauto/issues/109
894
+ return false;
895
+ }
896
+
875
897
  await setEnglishLang(false);
876
898
 
877
899
  await tryPressButton(await page.$x('//button[contains(text(), "Accept")]'), 'Accept cookies dialog');
@@ -900,11 +922,8 @@ const Instauto = async (db, browser, options) => {
900
922
  await sleep(1000);
901
923
 
902
924
  for (;;) {
903
- const loginButton = (await page.$x("//button[.//text() = 'Log In']"))[0];
904
- if (loginButton) {
905
- await loginButton.click();
906
- break;
907
- }
925
+ const didClickLogin = await tryClickLogin();
926
+ if (didClickLogin) break;
908
927
  logger.warn('Login button not found. Maybe you can help me click it? And also report an issue on github with a screenshot of what you\'re seeing :)');
909
928
  await sleep(6000);
910
929
  }