Estoy realizando, фрагментирующие а-ля página de es.stackoverflow.com, подставляют регистратора параграфа BeautifulSoup принципал el título y los votos que tiene cada pregunta en la página.
Ya он obtenido Лос titulares, pero se я сообщник la estructura de los votos que es la siguiente:
<div class="votes">
<div class="mini-counts">
<span title="0 votos">0</span></div>
<div>votos</div>
</div>
Leyendo otras publicaciones llegué que podría acceder través de los códigos CSS, que si no я equivoco en este caso sería:
"div.votes > div.mini-counts > span"
AL ejecutar el código, я aparece Комо respuesta una lista en blanco" []" Luego, ми código es el siguiente:
import requests
from bs4 import BeautifulSoup
import pandas as pd
page= requests.get("https://es.stackoverflow.com/questions?tab=newest&pagesize=50")
soup = BeautifulSoup(page.content,"html.parser")
tabla= soup.find(class_="snippet-hidden") #El soup find me permite encontrar un elemento
titulares = soup.find_all(class_="question-summary") #El soup me permite encontrar distintos elementos (2 o mas)
select_votos = soup.select("div.votes > div.mini-counts > span")
#pregunta= [item.find(class_="question-hyperlink").get_text() for item in titulares]
votos= [item.get("title") for item in select_votos]
print(votos)
Ты cГіdigo estГЎ правильный, за чем оно должно последовать, что все вопросы estГЎn с 0 обетами. В этом случае не производятся укрытые div. Когда нет votaciГіn в в вопросе только, производится
<div class="votes"/>
EdiciГіn:
на страницах es.stactkoverflow/questions классы: Последованные
selector="div.votes > span.vote-count-post > strong"
votos=[s.text for s in html.select(selector)]
print(votos)
:
['0', '0', '1', '0', '0', '0', '1', '1', '3', '1', '0', '-5', '0', '1', '1', '0', '0', '0', '0', '0', '0', '1', '3', '1', '2', '0', '1', '0', '3', '1', '4', '0', '1', '-2', '4', '3', '1', '3', '1', '0', '1', '2', '1', '1', '1', '0', '1', '3', '0', '0']
главная страница es.stackoverflow .com, если он содержит классы, которые ты показываешь.