Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop and read_lines()
#1
Hi,

I am working on a python project with selenium for webscraping.

If anyone's worked with selenium before, you know there is a send_keys() function that whatever variable/argument is passed in the (), it will be automatically typed into a form or a textarea.

There will be a .txt file in the folder of the project. Let's say text.txt. In this text file, there are like 10, 20, or even 100 of lines. Like this for example:

Line 1
Line 2
Line 3
...

I've tried different things but I just couldn't come up with a solution.

I want a loop (for or while) that allows the script, on each loop, to type in each line in the form.

I'm guessing we should say something like:

text=[]

to declare a new array. And then open and read each line of the file. Append it to this array and then loop through it.

Another problem I faced was that sometimes the loop would just use the first line and in the next loop it would use the same line again. Another problem was it just used all the lines in one loop. I think after each loop the value of let's say a variable "text" that has our current index of that array should be deleted and the next index (actually it's value) should be used.

And since in that function I told you send_keys(), we can use only one thing. Like a variable.

Please let me know if you have any solutions
Reply


Messages In This Thread
While loop and read_lines() - by pooria - Feb-05-2019, 08:12 AM
RE: While loop and read_lines() - by mlieqo - Feb-05-2019, 08:17 AM
RE: While loop and read_lines() - by buran - Feb-05-2019, 08:18 AM
RE: While loop and read_lines() - by pooria - Feb-05-2019, 08:30 AM
RE: While loop and read_lines() - by buran - Feb-05-2019, 08:32 AM
RE: While loop and read_lines() - by pooria - Feb-05-2019, 08:37 AM
RE: While loop and read_lines() - by buran - Feb-05-2019, 08:44 AM
RE: While loop and read_lines() - by pooria - Feb-05-2019, 08:52 AM
RE: While loop and read_lines() - by buran - Feb-05-2019, 09:01 AM
RE: While loop and read_lines() - by pooria - Feb-05-2019, 09:09 AM
RE: While loop and read_lines() - by buran - Feb-05-2019, 09:32 AM
RE: While loop and read_lines() - by pooria - Feb-06-2019, 09:18 AM
RE: While loop and read_lines() - by buran - Feb-06-2019, 10:05 AM
RE: While loop and read_lines() - by pooria - Feb-06-2019, 11:24 PM
RE: While loop and read_lines() - by buran - Feb-07-2019, 09:42 AM
RE: While loop and read_lines() - by pooria - Feb-07-2019, 09:46 AM
RE: While loop and read_lines() - by pooria - Feb-08-2019, 12:15 PM
RE: While loop and read_lines() - by buran - Feb-08-2019, 12:26 PM
RE: While loop and read_lines() - by pooria - Feb-08-2019, 01:22 PM
RE: While loop and read_lines() - by buran - Feb-08-2019, 06:19 PM
RE: While loop and read_lines() - by pooria - Feb-08-2019, 08:01 PM
RE: While loop and read_lines() - by buran - Feb-08-2019, 08:34 PM
RE: While loop and read_lines() - by pooria - Mar-11-2019, 10:59 AM
For-loop: Readlines + delete - by pooria - Feb-08-2019, 09:27 AM
RE: For-loop: Readlines + delete - by perfringo - Feb-08-2019, 10:58 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020