Skip to content

Commit 2a157d4

Browse files
authored
PR - Fix extract_text_from_element()and find_element*() to find_element() (InstaPy#6438)
* Updated getUserData() and find_element* Signed-off-by: elulcao <[email protected]> Thanks @breuerfelix for reviewing, 🚀 People in this thread please let me know if something is not OK, IG changed a lot these days. 🤗 @her
1 parent e62704a commit 2a157d4

16 files changed

+563
-472
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ tests/logs
115115

116116
# Pipfile
117117
Pipfile
118+
Pipfile.lock
118119

119120
# Instances
120121
z_*

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The **goal** of this file is explaining to the users of our project the notable
55
_The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)_
66

77

8+
## [0.6.16] - 2021-12-11
9+
10+
### Added
11+
12+
- Added filter in `extract_text_from_element()` for non-username elements.
13+
14+
### Fixed
15+
16+
- Fixed `is_private_profile()` when 'NoneType' object is not subscriptable
17+
- Fixed `find_element*()` to `find_element()`
18+
819
## [0.6.15] - 2021-12-02
920

1021
### Fixed

docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ comments=[
4343
{'mandatory_words': [["high", "tide"]], 'comments': ["High tides are better than low"]}
4444

4545
# Only "summer" AND ("lake" OR "occean") will satisfy this:
46-
{'mandatory_words': [["summer", ["lake", "occean"]], 'comments': ["Summer fun"]}
46+
{'mandatory_words': [["summer", ["lake", "occean"]]], 'comments': ["Summer fun"]}
4747

4848
]
4949
session.set_comments(comments)

instapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# flake8: noqa
22

33
# __variables__ with double-quoted values will be available in setup.py
4-
__version__ = "0.6.15"
4+
__version__ = "0.6.16"
55

66
from .instapy import InstaPy
77
from .util import smart_run

instapy/clarifai_util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Module which handles the clarifai api and checks
22
the image for invalid content"""
3-
from clarifai.rest import ClarifaiApp
4-
from clarifai.rest import Workflow
3+
from clarifai.rest import ClarifaiApp, Workflow
54
from selenium.common.exceptions import NoSuchElementException
5+
from selenium.webdriver.common.by import By
66

77
from .xpath import read_xpath
88

@@ -119,19 +119,19 @@ def get_source_link(browser):
119119

120120
try:
121121
source.append(
122-
browser.find_element_by_xpath(
123-
read_xpath(get_source_link.__name__, "image")
122+
browser.find_element(
123+
By.XPATH, read_xpath(get_source_link.__name__, "image")
124124
).get_attribute("src")
125125
)
126126
except NoSuchElementException:
127127
source.append(
128-
browser.find_element_by_xpath(
129-
read_xpath(get_source_link.__name__, "video")
128+
browser.find_element(
129+
By.XPATH, read_xpath(get_source_link.__name__, "video")
130130
).get_attribute("src")
131131
)
132132
source.append(
133-
browser.find_element_by_xpath(
134-
read_xpath(get_source_link.__name__, "image_alt")
133+
browser.find_element(
134+
By.XPATH, read_xpath(get_source_link.__name__, "image_alt")
135135
).get_attribute("src")
136136
)
137137

instapy/comment_util.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,45 @@
22
""" Module which handles the commenting features """
33
# import built-in & third-party modules
44
import random
5-
import emoji
65

7-
# import InstaPy modules
8-
from .time_util import sleep
9-
from .util import update_activity
10-
from .util import getMediaData
11-
from .util import add_user_to_blacklist
12-
from .util import click_element
13-
from .util import get_action_delay
14-
from .util import explicit_wait
15-
from .util import web_address_navigator
16-
from .util import evaluate_mandatory_words
17-
from .event import Event
18-
from .quota_supervisor import quota_supervisor
19-
from .xpath import read_xpath
6+
import emoji
207

218
# import exceptions
22-
from selenium.common.exceptions import WebDriverException
23-
from selenium.common.exceptions import InvalidElementStateException
24-
from selenium.common.exceptions import NoSuchElementException
9+
from selenium.common.exceptions import (
10+
InvalidElementStateException,
11+
NoSuchElementException,
12+
WebDriverException,
13+
)
2514
from selenium.webdriver.common.action_chains import ActionChains
15+
from selenium.webdriver.common.by import By
2616
from selenium.webdriver.common.keys import Keys
2717

18+
from .event import Event
19+
from .quota_supervisor import quota_supervisor
20+
21+
# import InstaPy modules
22+
from .time_util import sleep
23+
from .util import (
24+
add_user_to_blacklist,
25+
click_element,
26+
evaluate_mandatory_words,
27+
explicit_wait,
28+
get_action_delay,
29+
getMediaData,
30+
update_activity,
31+
web_address_navigator,
32+
)
33+
from .xpath import read_xpath
34+
2835

2936
def get_comment_input(browser):
30-
comment_input = browser.find_elements_by_xpath(
31-
read_xpath(get_comment_input.__name__, "comment_input")
37+
comment_input = browser.find_elements(
38+
By.XPATH, read_xpath(get_comment_input.__name__, "comment_input")
3239
)
3340

3441
if len(comment_input) <= 0:
35-
comment_input = browser.find_elements_by_xpath(
36-
read_xpath(get_comment_input.__name__, "placeholder")
42+
comment_input = browser.find_elements(
43+
By.XPATH, read_xpath(get_comment_input.__name__, "placeholder")
3744
)
3845

3946
return comment_input
@@ -45,8 +52,8 @@ def open_comment_section(browser, logger):
4552
"\t~may cause issues with browser windows of smaller widths"
4653
)
4754

48-
comment_elem = browser.find_elements_by_xpath(
49-
read_xpath(open_comment_section.__name__, "comment_elem")
55+
comment_elem = browser.find_elements(
56+
By.XPATH, read_xpath(open_comment_section.__name__, "comment_elem")
5057
)
5158

5259
if len(comment_elem) > 0:
@@ -265,8 +272,8 @@ def get_comments_on_post(
265272
explicit_wait(browser, "PFL", [], logger, 10)
266273

267274
try:
268-
all_comment_like_buttons = browser.find_elements_by_xpath(
269-
like_button_full_XPath
275+
all_comment_like_buttons = browser.find_elements(
276+
By.XPATH, like_button_full_XPath
270277
)
271278

272279
if all_comment_like_buttons:
@@ -290,8 +297,8 @@ def get_comments_on_post(
290297
logger.info("Could not grab any commenter from this post")
291298

292299
else:
293-
comment_unlike_buttons = browser.find_elements_by_xpath(
294-
unlike_button_full_XPath
300+
comment_unlike_buttons = browser.find_elements(
301+
By.XPATH, unlike_button_full_XPath
295302
)
296303

297304
if comment_unlike_buttons:

0 commit comments

Comments
 (0)