Skip to content

Commit 64bab19

Browse files
author
ProgrammingIncluded
committed
v0.3.0: Remove Ads and Average Scrolling
1 parent 0df572e commit 64bab19

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 0.3.0: Remove Ads and Average Scrolling
4+
5+
* Add average scrolling to compensate for scroll heights
6+
* Add Ad removal logic
7+
38
## 0.2.0: Enable Login and New Scroll Method
49

510
* Add `--login` for giving users login

birdwatch.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ def calc_average(lst):
8585
s = sorted(lst)[cut_off:len(lst) - cut_off]
8686
return sum(s) / len(s)
8787

88+
def remove_ads(driver):
89+
return driver.execute_script("""
90+
var elems = document.querySelectorAll("*"),
91+
res = Array.from(elems).find(v => v.textContent == 'Promoted Tweet');
92+
93+
if (res) {
94+
let p = res.parentNode.parentNode.parentNode;
95+
p.innerHTML="";
96+
return true;
97+
}
98+
return false;
99+
""")
100+
101+
88102
def fetch_html(driver, url, fpath, load_times, force=False, number_posts_to_cap=SCRAPE_N_TWEETS, bio_only=False):
89103
driver.get(url)
90104
state = ""
@@ -180,6 +194,10 @@ def fetch_html(driver, url, fpath, load_times, force=False, number_posts_to_cap=
180194
div_track.add(div_id)
181195
driver.execute_script("return arguments[0].scrollIntoView();", tweet)
182196
driver.execute_script("window.scrollTo(0, window.pageYOffset - 50);")
197+
198+
ad = remove_ads(driver)
199+
if ad:
200+
continue
183201
except:
184202
continue
185203

0 commit comments

Comments
 (0)