简体   繁体   中英

What would be the best way to handle multiple actions in Python browser automation (with Selenium)?

I am writing a program in python that uses selenium to automate bidding for me on a website. In the bidding section of the website, they often list the prizes and their "Time Remaining" counting down. There are small prizes and larger prizes. The larger prizes require more tickets to win because there are more people who want to enter into them (it is based on probability and how many tickets you enter).

For the small prizes, I have enough tickets that I can just bid on them as they come and before their timer runs out. However, for the large prizes, the rate that I get tickets is not enough to bid on small prizes and then suddenly bid on a large prize when the timer gets close to zero. Since you can bid multiple times on the same prize, I decided I want to bid incrementally for the large prizes and only use a portion of my tickets until I get up to my "goal" amount of tickets for that prize.

The problem is that while I have one function that is continuously running, bidding on the small prizes (the page refreshes after each bid and all bids are on the same page), I would also like to set some kind of timer in my program that tells it to bid every, say, 2 minutes on a large prize until the amount of tickets I want to bid for that prize is reached. So should I open up a new browser window with selenium for the large prizes? Or should I try to somehow fit the bidding of the large prizes in with the smaller ones and use the same browser window?

I kind of would like to be able to do the second for "simplification" purposes but I'm not sure how I would fit in the timed bidding of the large prizes with the somewhat random bidding on the small prizes.

Thanks.

Here is a small code snippet in C# where you set the Bidding Interval/Time remaining.

Once Time/Interval is completed it fires an event *LargePrize_Tick* which in turn will bid on Large prizes till you run out of tickets.

static void Timer_Ticking(int Interval_in_Secs)
    {
        Timer timer = new Timer(); 
        timer.Interval = (1000) * (1);              // Timer will tick evert second
        timer.Enabled = true;                       // Enable the timer
        timer.Start();                              // Start the timer
        timer.Interval = Interval_in_Secs*1000;    //Equvivalent in milliseconds.
        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(Interval_in_Secs));
        timer.Elapsed += new ElapsedEventHandler(LargePrize_Tick);
    }

    static void LargePrize_Tick(object sender, EventArgs e)
    {
        Console.WriteLine("Done with interval ");

        //Open Browsers
        //Bid for Prize till ticket is Available
        //Close browser after bidding.

    }

I hope this Helps....all the best :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM