przeszukiwanie strony groupy, tworzenie listy linków do eventów

This commit is contained in:
liza 2021-06-09 23:54:42 +02:00
parent 85972a03a6
commit ce56eae03e

55
get_events_FB.py Normal file
View File

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
import sys
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import re
#login
url = 'https://www.facebook.com/login/'
browser = webdriver.Firefox()
browser.get(url)
#cookie
accept = browser.find_element_by_xpath("//button[@title='Akceptuj wszystkie']")
accept.click()
#login
login = browser.find_element_by_id("email")
password = browser.find_element_by_id("pass")
login_button = browser.find_element_by_id("loginbutton")
sing_in = ActionChains(browser)
sing_in.click(on_element = login)
sing_in.send_keys("+48 883 763 414")
sing_in.click(on_element = password)
sing_in.send_keys("23facebook11")
sing_in.click(on_element = login_button)
sing_in.perform()
#wait until new page is loaded
time.sleep(5)
#go to group page
url = 'https://facebook.com/groups/babacoolpoznan/'
browser.get(url)
time.sleep(3)
#scrolling
i = 0
for _ in range(5):
browser.execute_script("window.scrollTo(0, " + str(900+i) + ");")
i += 500
time.sleep(3)
#get_events
html_page = browser.page_source
substring = '\/events\/.*?\?'
pattern = re.compile(substring)
result = re.findall(pattern, html_page)
del result[::3]
del result[::2]
links = []
for r in result:
links.append(r.split(" ")[0][:-1])
print(links)