Pyhon: Bucle no Recorre una Lista
Publicado por Matias (2 intervenciones) el 30/08/2019 03:51:55
Hola,
Buenas Noches , Saludos desde Argentina, Tengo el siguiente codigo y un bucle while (linea 72) que no recorre una lista de elementos almacenados previamente (repite la 1era posicion) , les agradezco su ayuda de ante mano
Buenas Noches , Saludos desde Argentina, Tengo el siguiente codigo y un bucle while (linea 72) que no recorre una lista de elementos almacenados previamente (repite la 1era posicion) , les agradezco su ayuda de ante mano
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from selenium import webdriver
from selenium.webdriver.common.by import By
import selenium.webdriver.common.keys
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import time
import os
def encontrar(lista):
lista_grupos = []
lista_palabras_claves = lista
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("--disable-extensions")
option.add_experimental_option("prefs", {
"profile.default_content_setting_values.notifications": 1
})
browser = webdriver.Chrome(chrome_options=option, executable_path=r"chromedriver.exe")
browser.get('https://www.facebook.com/')
time.sleep(1)
browser.find_element_by_id("email").send_keys(correo)
time.sleep(1)
browser.find_element_by_id("pass").send_keys(password)
time.sleep(1)
browser.find_element_by_xpath("//input[contains(@data-testid,'royal_login_button')]").click()
time.sleep(1)
for palabras_claves in lista_palabras_claves:
browser.get("https://www.facebook.com/groups/")
time.sleep(5)
browser.get("https://www.facebook.com/search/groups/?q={}&epa=SERP_TAB".format(palabras_claves))
time.sleep(2)
for x in range(0,1):
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(5)
listas = []
listas = browser.find_elements_by_xpath("//div[contains(@data-testid,'browse-result-content')]")
time.sleep(5)
f = open("grupos.txt", "a", encoding="utf-8")
elemento = 0
while elemento < len(listas):
enlace = listas[elemento].find_element_by_xpath("//a[starts-with(@href,'/groups/')]").get_attribute('href')
print(enlace)
nombre = listas[elemento].find_element_by_xpath("//div[contains(@style,'webkit')]").text
print(nombre)
miembros = listas[elemento].find_element_by_xpath("//div[contains(@class,'_pac')]").text
print(miembros)
f.write("{},{},{} \n".format(nombre,miembros,enlace))
time.sleep(2)
elemento += 1
f.close()
encontrar(["argentina"])
Valora esta pregunta


0