DuduCreator
DuduCreator

Reputation: 3

How do I extract text from a webpage?

I had this project idea roaming trough my head for some days. My classmates found this game (it's in romanian, but it doesn't matter) in which you need to match the prompted mountain with the correct point on the map. I want to automate a bit this process with python.

I was thinking of maybe using tesseract to identify the text displayed on the page, but I couldn't find any information about tesseract recognizing text in real time. I would maybe need to take a screenshot, feed it into tesseract, get the text, move the mouse to the correct point and then delete the screenshot. Is there any better way to do it? Maybe I can read the html code of the webpage when it changes the mountain it is asking for?

The part with moving the mouse I have already figured out. I have the coordinates saved in a dict, and, for now, I matched them with the first three letters of the mountains. Obviously, this is not fast enough.

Note: I am on a Windows machine and I won't use this for cheating, it is just a fun project.

My code:

import mouse

coords = {
    "olt": (811, 831),
    "cea": (589, 806),
    "jiu": (613, 790),
    "rm": (819, 751),
    "pit": (937, 826),
    "meh": (474, 797),
    "iov": (485, 778),
    "cer": (459, 755),
    "tar": (464, 687),
    "god": (504, 718),
    "ret": (540, 681),
    "hat": (553, 640),
    "pet": (627, 675),
    "par": (658, 712),
    "val": (585, 731),
    "hun": (543, 531),
    "sur": (602, 599),
    "gal": (687, 582),
    "can": (722, 591),
    "lot": (772, 639),
    "vid": (723, 658),
    "cap": (750, 714),
    "sib": (787, 555),
    "lov": (817, 664),
    "coz": (832, 693),
    "fru": (871, 689),
    "ghi": (897, 687),
    "lac": (880, 663),
    "fag": (865, 603),
    "iez": (950, 660),
    "pia": (996, 637),
    "cul": (1020, 644),
    "lea": (1001, 681),
    "buc":(1045, 665),
    "bra": (1071, 627)
}

while True:
    query = input("relief: ")
    mouse.move(coords[query][0], coords[query][1])
    mouse.click()

Upvotes: 0

Views: 54

Answers (0)

Related Questions