I'm trying to automate searching for ads in Facebook Ads Library. For that, I've used Selenium and BeautifulSoup to get the page's code.
The BeautifulSoup function returns a bs4.ResultSet with the page's HTML, which as I understand is a list.
I'm trying to loop through that list with soup.find_all, and for each element that is found, I want to test and see if there's a specific string in that.
But actually, my code isn't working as expected. The if statement inside the for loop always returns False.
# Using chrome driver
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
# Web page url request
driver.get('https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=BR&q=frete%20gr%C3%A1tis%20aproveite&sort_data[direction]=desc&sort_data[mode]=relevancy_monthly_grouped&search_type=keyword_unordered&media_type=all')
driver.maximize_window()
time.sleep(10)
# Webscraping with BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'html.parser')
ads_list = []
for tag in soup.find_all('div', class_='_99s5'):
if 'qku1pbnj j8otv06s r05nras9 a1itoznt te7ihjl9 svz86pwt a53abz89' in str(tag):
ads_list.append(tag)
else:
None