lundi 23 décembre 2019

Python get text from HTML Website currently opened in browser

So i'm in my second year of university and we do a lot of programming in java but i'd like to do AI Stuff / Data Science later for a living so i've decided to learn pyhton (gotta say i really miss those brackets). My first project was a simple calculator that saves all calculations done to a file and is able to read all calculations from that file (just so you know how far i am with pyhton).

Yesterday i've stumbled over TypeRacer, a very simple game about beeing able to type fast. I thought it'd be fun to write a bot for this as it's probably not that difficult and i'll get to learn some new tricks in pyhton which may be usefull later like getting data from web-pages.

My initial plan was to just copy the text you'll have to type, paste it into the console and then as soon as you klick with the mouse, the programm will write the text. The writing-part turned out to be really easy:

import pyautogui

def main():
 pyautogui.press('a')

Is basically all i need. However getting the text turned out to be really difficult as you can't just copy the text from the game-field as the website doesn't allow you to. You can however get into the Developer-Console, choose inspect element and from there you can copy the text within the . This is the process i'd like to automate: Hook into the browser i have currently open on my (windows) pc and get the text of a div.

I am not even sure if this is possible as this question suggest that you can't get all opened websites of a browser so what i'm trying to to may not be possible as well.

TLDR: I want to cheat in TypeRacer and i need to get the text you have to type programmatically. I can't just copy the text into the console as the website doesn't allow that.




Aucun commentaire:

Enregistrer un commentaire