Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping with Beautifulsoup
#3
(Jan-22-2019, 04:20 PM)ichabod801 Wrote: You can only go through a file object once. You do that on line 7 when you use the readlines method. So then on line 18 you read nothing, because you've already read the file.

I would suggest getting rid of urlcount and numberoflines, and looping over the file directly.

with open('input.txt') as url_file:
    for my_url in url_file:
        uClient = uReq(my_url.strip())
        ...

The idea is great, it's much shorter and easier this way, however, I get a syntax error at the "as" in while open('input.txt') as url_file: thich I don't really understand why. I am using python 3.7.
Reply


Messages In This Thread
Looping with Beautifulsoup - by CaptainCsaba - Jan-22-2019, 11:55 AM
RE: Looping with Beautifulsoup - by ichabod801 - Jan-22-2019, 04:20 PM
RE: Looping with Beautifulsoup - by CaptainCsaba - Jan-23-2019, 07:17 AM
RE: Looping with Beautifulsoup - by buran - Jan-23-2019, 09:41 AM
RE: Looping with Beautifulsoup - by CaptainCsaba - Jan-23-2019, 10:49 AM
RE: Looping with Beautifulsoup - by snippsat - Jan-23-2019, 11:18 AM
RE: Looping with Beautifulsoup - by buran - Jan-23-2019, 11:20 AM
RE: Looping with Beautifulsoup - by CaptainCsaba - Jan-23-2019, 11:30 AM
RE: Looping with Beautifulsoup - by buran - Jan-23-2019, 12:38 PM

Forum Jump:

User Panel Messages

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