Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with for loop
#2
Can you run
import urllib.request, re
 
with open("test.txt", "r") as url_file:
    for line in url_file:
        line = line.strip()
        print(line)
        text = urllib.request.urlopen(line).read().decode('utf-8')
this way we shall see which url creates a problem, i.e. do you get to the end of the list. But it looks like you have empty lines at the end of the urls file...

note the changes I have made and which you should keep.
Also parsing html with regex is big NO. HTML should not be used with regex read You can't parse [X]HTML with regex
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Problem with for loop - by Blue Dog - Jul-09-2018, 03:21 PM
RE: Peoblem with for loop - by buran - Jul-09-2018, 04:27 PM
RE: Problem with for loop - by Blue Dog - Jul-09-2018, 05:33 PM
RE: Problem with for loop - by buran - Jul-09-2018, 05:35 PM
RE: Problem with for loop - by Blue Dog - Jul-09-2018, 05:43 PM
RE: Problem with for loop - by buran - Jul-09-2018, 06:46 PM
RE: Problem with for loop - by Blue Dog - Jul-09-2018, 07:07 PM
RE: Problem with for loop - by nilamo - Jul-09-2018, 07:58 PM
RE: Problem with for loop - by Blue Dog - Jul-10-2018, 01:31 AM
RE: Problem with for loop - by buran - Jul-10-2018, 05:50 AM
RE: Problem with for loop - by Blue Dog - Jul-10-2018, 07:13 PM
RE: Problem with for loop - by Blue Dog - Jul-10-2018, 11:21 PM

Forum Jump:

User Panel Messages

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