sia
gesperrt
Hi Leute,
Ich hab folgendes Script:
[src=python]#!/usr/bin/env python3
from splinter import Browser
from time import sleep
from urllib import parse
### global variables
answers = {}
answers['plz'] = '12345'
answers['provider'] = 'Unitymedia'
answers['providerId'] = '450'
answers['speed'] = '400 Mbit/s'
answers['speedVal'] = '400000'
answers['speedId'] = '53192'
answers['tarif'] = '2play FLY 400'
answers['tarifId'] = '53205'
### do not change anything below this line
browser = Browser('chrome')
browser.visit('https://breitbandmessung.de/test')
# click "start"
print('Clicking start…')
browser.find_by_css('.question-0 .button-blue-big-start').first.click()
# wait a bit while the JS animation plays
sleep(1)
# answer "Ja" to the question if you're using an Ethernet cable
print('Answering that we\'re using a LAN cable…')
browser.find_by_css('label[for="lan-ja"]').first.click()
browser.find_by_css('.question-5 .button-blue-big-forward').first.click()
sleep(1)
# answer "Ja" to the question whether you eliminated influence factors
print('Answering that we eliminated influence factors…')
browser.find_by_css('label[for="optimal-ja"]').first.click()
browser.find_by_css('.question-10 .button-blue-big-forward').first.click()
sleep(1)
# input Postleitzahl
print('Filling PLZ…')
browser.fill('plz', answers['plz'])
browser.find_by_css('.question-20 .button-blue-big-forward').first.click()
sleep(1)
#select provider (over ID)
print('Filling provider…')
browser.execute_script('$("#provider").val("'+answers['providerId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-30 .button-blue-big-forward').first.click()
sleep(1)
# select speed (over ID)
print('Filling speed…')
browser.execute_script('$("#speed").val("'+answers['speedId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-40 .button-blue-big-forward').first.click()
sleep(1)
# select tariff (over ID)
print('Filling tariff…')
browser.execute_script('$("#tarif").val("'+answers['tarifId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-50 .button-blue-big-forward').first.click()
sleep(1)
# select "no limit" for download limits
print('Selecting "no limit"…')
browser.find_by_css('label[for="limit-nein"]').first.click()
browser.find_by_css('.question-120 .button-blue-big-forward').first.click()
sleep(1)
# start the test
print('Starting the test…')
browser.find_by_css('.question-60').find_by_text('5').first.click()
browser.find_by_css('.question-60 .button-blue-big-forward').first.click()
sleep(1)
# wait for completion
print('Waiting…')
if browser.is_text_present('Messung abgeschlossen', wait_time=70):
print('Measurement complete!')
sleep(5)
# print results
browser.execute_script('showdetails.click()')
results = {}
results['download'] = browser.evaluate_script('$(".results-download .results-val").text()')
results['upload'] = browser.evaluate_script('$(".results-upload .results-val").text()')
results['ping'] = browser.evaluate_script('$(".results-ping .results-val").text()')
results['id'] = browser.evaluate_script('$(".test-details .val-id").text()')
print(results)
[/src]
Und folgendes Pipfile:
[src=python][[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[packages]
splinter = "*"[/src]
(Laufen lassen mit pipenv run python breitbandmessung.py3)
Würde das jetzt gerne so umschreiben, dass das Script nicht mehr wild irgendwelche Buttons klickt, sondern die vom Speedtest intern verwendeten Variablen und .click-Funktionen nutzt (wie bei "print results" schon getan). Allerdings komme ich nicht an die Variablen im Array internal dran… Ich checke im JS-Code der Seite allerdings auch nicht, wo genau sie die internen Variablen löschen, sonst könnte man diese Funktion ja überschreiben bzw. überladen.
Ich hab folgendes Script:
[src=python]#!/usr/bin/env python3
from splinter import Browser
from time import sleep
from urllib import parse
### global variables
answers = {}
answers['plz'] = '12345'
answers['provider'] = 'Unitymedia'
answers['providerId'] = '450'
answers['speed'] = '400 Mbit/s'
answers['speedVal'] = '400000'
answers['speedId'] = '53192'
answers['tarif'] = '2play FLY 400'
answers['tarifId'] = '53205'
### do not change anything below this line
browser = Browser('chrome')
browser.visit('https://breitbandmessung.de/test')
# click "start"
print('Clicking start…')
browser.find_by_css('.question-0 .button-blue-big-start').first.click()
# wait a bit while the JS animation plays
sleep(1)
# answer "Ja" to the question if you're using an Ethernet cable
print('Answering that we\'re using a LAN cable…')
browser.find_by_css('label[for="lan-ja"]').first.click()
browser.find_by_css('.question-5 .button-blue-big-forward').first.click()
sleep(1)
# answer "Ja" to the question whether you eliminated influence factors
print('Answering that we eliminated influence factors…')
browser.find_by_css('label[for="optimal-ja"]').first.click()
browser.find_by_css('.question-10 .button-blue-big-forward').first.click()
sleep(1)
# input Postleitzahl
print('Filling PLZ…')
browser.fill('plz', answers['plz'])
browser.find_by_css('.question-20 .button-blue-big-forward').first.click()
sleep(1)
#select provider (over ID)
print('Filling provider…')
browser.execute_script('$("#provider").val("'+answers['providerId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-30 .button-blue-big-forward').first.click()
sleep(1)
# select speed (over ID)
print('Filling speed…')
browser.execute_script('$("#speed").val("'+answers['speedId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-40 .button-blue-big-forward').first.click()
sleep(1)
# select tariff (over ID)
print('Filling tariff…')
browser.execute_script('$("#tarif").val("'+answers['tarifId']+'").trigger("chosen:updated");')
browser.find_by_css('.question-50 .button-blue-big-forward').first.click()
sleep(1)
# select "no limit" for download limits
print('Selecting "no limit"…')
browser.find_by_css('label[for="limit-nein"]').first.click()
browser.find_by_css('.question-120 .button-blue-big-forward').first.click()
sleep(1)
# start the test
print('Starting the test…')
browser.find_by_css('.question-60').find_by_text('5').first.click()
browser.find_by_css('.question-60 .button-blue-big-forward').first.click()
sleep(1)
# wait for completion
print('Waiting…')
if browser.is_text_present('Messung abgeschlossen', wait_time=70):
print('Measurement complete!')
sleep(5)
# print results
browser.execute_script('showdetails.click()')
results = {}
results['download'] = browser.evaluate_script('$(".results-download .results-val").text()')
results['upload'] = browser.evaluate_script('$(".results-upload .results-val").text()')
results['ping'] = browser.evaluate_script('$(".results-ping .results-val").text()')
results['id'] = browser.evaluate_script('$(".test-details .val-id").text()')
print(results)
[/src]
Und folgendes Pipfile:
[src=python][[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[packages]
splinter = "*"[/src]
(Laufen lassen mit pipenv run python breitbandmessung.py3)
Würde das jetzt gerne so umschreiben, dass das Script nicht mehr wild irgendwelche Buttons klickt, sondern die vom Speedtest intern verwendeten Variablen und .click-Funktionen nutzt (wie bei "print results" schon getan). Allerdings komme ich nicht an die Variablen im Array internal dran… Ich checke im JS-Code der Seite allerdings auch nicht, wo genau sie die internen Variablen löschen, sonst könnte man diese Funktion ja überschreiben bzw. überladen.