From 34895a251891b56eff10a5ba04866487741717cb Mon Sep 17 00:00:00 2001 From: wes Date: Mon, 7 Sep 2020 20:07:10 -0400 Subject: [PATCH] force url to mobile site for deleting wall posts --- deletefb/tools/common.py | 9 +++++++++ deletefb/tools/wall.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deletefb/tools/common.py b/deletefb/tools/common.py index bb24989..6c4a1a6 100644 --- a/deletefb/tools/common.py +++ b/deletefb/tools/common.py @@ -12,6 +12,7 @@ import json import logging import logging.config import os +import urllib.parse as urlparse SELENIUM_EXCEPTIONS = ( NoSuchElementException, @@ -67,6 +68,14 @@ def wait_xpath(driver, expr): except SELENIUM_EXCEPTIONS: return +def force_mobile(url): + """ + Force a url to use the mobile site. + """ + parsed = urlparse.urlparse(url) + if parsed.netloc == "www.facebook.com": + return f"https://mobile.facebook.com{parsed.path}" + return url NO_CHROME_DRIVER = """ You need to manually install the chromedriver for Selenium\n diff --git a/deletefb/tools/wall.py b/deletefb/tools/wall.py index 8cc4d27..fd97862 100644 --- a/deletefb/tools/wall.py +++ b/deletefb/tools/wall.py @@ -1,6 +1,6 @@ from ..types import Post from .archive import archiver -from .common import SELENIUM_EXCEPTIONS, click_button, wait_xpath +from .common import SELENIUM_EXCEPTIONS, click_button, wait_xpath, force_mobile from .config import settings from selenium.webdriver.common.action_chains import ActionChains @@ -24,6 +24,8 @@ def delete_posts(driver, if year is not None: user_profile_url = "{0}/timeline?year={1}".format(user_profile_url, year) + user_profile_url = force_mobile(user_profile_url) + driver.get(user_profile_url) finished = False