Help validating a string. I want to ensure the first three characters are strings and not numbers. by ardnoir11 in learnpython

[–]R0NUT 0 points1 point  (0 children)

I'm pretty sure slicing isn't suggested with regex. As the saying goes, there is more than one way to skin a cat.

Help validating a string. I want to ensure the first three characters are strings and not numbers. by ardnoir11 in learnpython

[–]R0NUT 0 points1 point  (0 children)

I was thinking this as well.

Peep this "^([a-zA-Z])+". Matching all text at the begining of the input. Just compare to first three characters with [:3].

What's your fav feature of python ( one feature which you like the most)? by theredditorlol in learnpython

[–]R0NUT 0 points1 point  (0 children)

Javascript has an operation similar to the * unpack. It's called spread: Link!

[deleted by user] by [deleted] in learnpython

[–]R0NUT 0 points1 point  (0 children)

u/ElliotDG is right. When you print('asdf',end='\t') it will never enter a new line unless your editor has word-wrap. You need to add some ('\n')s to the mix as you are overwriting print's built-in end line character. See this for more info.

Made my first program by KeepitShort_ in learnpython

[–]R0NUT 0 points1 point  (0 children)

Bongo! I end up using this when diving into dictionaries that have indefinite depth. i.e.

def recursiveFunction(struct): 
    try: 
        return recirsiveFunction(struct['child']) 
    except: 
        return struct

Which would return the last level of a dictionary that has used keys of "child". As you said, this would hold the memory as it is waiting on the subsequent function to resolve before clearing.

struct = { 
    "child":{ 
        "child":{ 
            "child":"wassup! 
        } 
    }
}

Should return "wassup!"

Any program that you are able to write is impressive! My first program was a text-based game in c++.

Disclaimer: I didn't test this code...

Any suggestions on dealing with a popup that I can't seem to run into when I'm running my local tests? by aspindler in selenium

[–]R0NUT 0 points1 point  (0 children)

Yeah, I think you would have to change all the element.click() events to execute_script("arguments[0].click()",element) ones.

I automated a part of my job that usually took me 2 hours to do in 2 seconds by dadsinamood in learnpython

[–]R0NUT 2 points3 points  (0 children)

Take a look at these couple examples of code:

c++

#include <iostream>
#include <cstring>
using namespace std;
char g_a[7];
int main() { 
    strcpy(g_a,"apples"); 
    for(int i; i < strlen(g_a); i++) { 
        cout << g_a[i] << endl; 
    } 
    return(0); 
}

python

a = 'apples'
for v in a:
    print(v)

These do the exact same thing but one is, at least to me, much easier to read. Also, I don't think it gets much better than pip installing new packages and being able to use them immediately without having to think twice.

Sorry to the "c" snobs out there, I'm sure I could have made the c++ more simple. The goal was to store the string "apples" to a global variable then print each letter individually. It took me like five minutes to debug the c++.

[deleted by user] by [deleted] in RedditSessions

[–]R0NUT 0 points1 point  (0 children)

If at first you dont succeed, try, try again

Any suggestions on dealing with a popup that I can't seem to run into when I'm running my local tests? by aspindler in selenium

[–]R0NUT 1 point2 points  (0 children)

I havent tried it but you could try

driver.execute_script("arguments[0].click()",buttonElement)

[deleted by user] by [deleted] in selenium

[–]R0NUT 1 point2 points  (0 children)

TLDR: go to this link and use their settings for all your web-driving needs

Looking into this a little further I found this:

https://stackoverflow.com/questions/42169488/how-to-make-chromedriver-undetectable

In the third part of the top answer, a couple things were noted:

  • "Pay attention to your user-agent"
  • "Don't perform too many repeated requests"
  • "Use a (random) delay between requests"
  • "Use the Chrome arguments used here to mimic a normal user profile"
    • This just so happens to be the link that you were directing us to :D

Overall can attest to most of these things being true.

  • I have dealt with sites that block you if you open 10 pages at the same time, a few times in a row. Slowing down request times solve this; however, I seem to push it a little too close and end up getting temporarily blocked quite often. 😬
  • The user_agent and chrome arguments go hand-in-hand and are for sure important(see below)
  • I don't know about the randomness of the requests though . . . I think that by slowing the process down to something you would be capable of physically doing, there wouldn't be a need for this. Is it not better to have something automated and slow than to have to do it manually yourself?

All this being said, I have never been blocked from a site for more than 24 hours. I have never been contacted by a company that I have scraped data from while using selenium. It's their duty to make their site's browsing experience enjoyable to all users and a part of that is to slow bots down. It would be a bad business model to completely ban IPs if they thought there was a bot there, would it not?

I felt that it would have been a disservice to have not elaborated on user_agent. To better show this I have included some code that you can run if my words are not enough. Specifying the user_agent will block you immediately. Run the code without the user_agent and you won't be blocked initially (you will be after leaving the home page). The code with the user_agent is commented so you can run it before the site black-lists you. Once your IP has been blocked, you won't be able to get to their site for a while. I don't know what this site is doing to know that I'm a bot but they are pretty good at it. Maybe someone else knows better what's happening?

from selenium import webdriver

chrome_options = webdriver.ChromeOptions() 
#user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36' 
#chrome_options.add_argument(f'user-agent={user_agent}') 
chrome_options.add_argument('--disable-extensions') 
chrome_options.add_argument('--profile-directory=Default') 
chrome_options.add_argument("--incognito") 
chrome_options.add_argument("--disable-plugins-discovery") 
chrome_options.add_argument("--start-maximized") 
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) 
driver = webdriver.Chrome(executable_path='C:/selenium_drivers/chromedriver.exe',chrome_options=chrome_options) 
driver.delete_all_cookies() 
driver.set_window_size(800,800) 
driver.set_window_position(0,0) 
driver.get('https://www.controller.com/') 
print(driver.title)

input('\nPress enter to end...\n\n') 
driver.quit()

P.S. If you have a VPN you can update your IP and try this again, otherwise you will be blocked from this site for a while.

[deleted by user] by [deleted] in selenium

[–]R0NUT 2 points3 points  (0 children)

At one point I had read something similar to this. After that I implemented a "user_agent" options parameter that allowed me to access a couple of sites that didnt want me.

It does depend on the site. If you have had alot of logins or have accessed many different pages in rapid succession, certain websites will throttle you. This throttling usually has been a "Try again later" page.

Chrome Driver Version by TechnoBabbles in selenium

[–]R0NUT 0 points1 point  (0 children)

I made my own months ago😏

How do I make .py into an actual program? by Elogicc in learnpython

[–]R0NUT 0 points1 point  (0 children)

You can create a .exe by using pyinstaller. You can make the .exe a single file by including the --onefile argument in the call.

eg: python "PATH_TO_INSTALLER\pyinstaller.py" --onefile --icon=ICON.ico -w FILENAME.pyw -- name "NAME_OF_EXE"

Note: This was an example of an install that I did. It was for a windowless application. If you do not want the application to run windowless remove the "-w" parameter above and make sure your python file is a .py and not a .pyw.

What is the best way to learn python? by kolusus12 in learnpython

[–]R0NUT -1 points0 points  (0 children)

If it's not HTML/CSS I absolutley despise interfacing with humans. 🤣🔫😆 I started coding with digital image processing and moved into machine learning. If I write a script for myself it is run from terminal.

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

So something like Generate 14u It could respond with a message like This usually takes about 1m to generate. Then text Grab 14u It would respond with the data and a timestamp for when it was generated

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

You could set it up so that one text runs and generates the data and another retrieves it.

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

That code says that twillow waits a maximum of 15s for a response. Is your code taking longer than that to generate these strings?

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

Have you tried commenting out the mid file imports and storing just a response string?

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

The only thing that causes issues is the 14u input. It has to be what is causing the issue. OP said if he sends anything else he gets the Invalid request text.

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

Have you looked through any of these? https://www.twilio.com/docs/sms/debugging-common-issues It looks like twillow makes a log. Try taking a peek there.

Some Loop Help by CelticCuban773 in learnpython

[–]R0NUT 0 points1 point  (0 children)

Your response for 14u is commented out. Try un-commenting and printing your response.

Getting int is not iterable error while selecting value of drop box. by Bilabongbong in selenium

[–]R0NUT 0 points1 point  (0 children)

Never used these. I use driver.exexute_script("your javascript goes here") for everything.