With requests will not give because it does not process Javascript, if you do:
import requests
req = requests.get("http://soulegal.byethost7.com/wp/2016/07/28/pesquisa-eu-sou-legal/")
print(req.status_code)
print(req.text)
You can see what you print:
200
...This site requires Javascript to work, Please enable Javascript in your browser or use a browser with Javascript support...
This basically tells us that the request (request) was successful (code 200) but we need a browser (browser), or something that processes javascript implicitly (unknown). However good programmers have developed a module called Selenium that makes it all automatically (open the browser, select, submit the form, ect...). And pussui a documentation well-structured:
To vote on several options:
from selenium import webdriver
driver = webdriver.Firefox()
opts = ['poll-answer-6', 'poll-answer-7', 'poll-answer-8'] # id das opcoes em que deseja votar
for i in opts:
driver.get("http://soulegal.byethost7.com/wp/2016/07/28/pesquisa-eu-sou-legal/?ckattempt=1")
opt = driver.find_element_by_id(i) # selecionamos o elemento com id
opt.click()
btn_submit = driver.find_element_by_name('vote') # selecionamos o elemento que como name tem 'vote', o nosso botao
btn_submit.click()
print('Votou em {}'.format(driver.find_element_by_css_selector('label[for="' +i+ '"]').text))
To select the same option several times, in this case 5 times:
from selenium import webdriver
driver = webdriver.Firefox()
opt = 'poll-answer-7' # id opcao em que deseja votar
votos = 5
for i in range(votos):
driver.get("http://soulegal.byethost7.com/wp/2016/07/28/pesquisa-eu-sou-legal/?ckattempt=1")
opt_ele = driver.find_element_by_id(opt)
opt_ele.click()
btn_submit = driver.find_element_by_name('vote')
btn_submit.click()
opt_text = driver.find_element_by_css_selector('label[for="' +opt+ '"]').text
print('Votou em {} {} vezes'.format(opt_text, votos))
I managed to run the code on Kali Linux. It worked. Thank you very much. All that remains is for me to understand the code.
– Ed S
If you want to open a chat and I’ll explain step by step. I’m glad it worked @Edmail
– Miguel
If you can, I’d appreciate it!
– Ed S