Jump to content
Dante Unbound: Share Bug Reports and Feedback Here! ×

Can anyone explain why python is looping constantly?


SigweardStoneFist
 Share

Recommended Posts

I have been trying to make a web scraper, but python keeps looping even after it's done with the for() loop.

Please note that I'm pretty new to it and my unlogic methods usually work so why this isn't is confusing me.

Here's the code(rewrote it out of my head as I don't have to code with me atm).

import request
from bs4 import BeautifulSoup

page = requests.get(input('URL: '))
txt = page.text
soup = BeautifulSoup(txt, "html.parser")
all_tables = soup.find_all(input('Searching for?: '))

class scraper(object):
       def __contains__(self, string1, string2):
             self.string1 = string1
             self.string2 = string2
             for string2 in string1:
                 for x in string2:
                     if x != '':
                        print (x[0:len(string2)])

ce = scraper()
ce.__contains__(soup, all_tables)

print (ce)

 

Link to comment
Share on other sites

  • 2 weeks later...
13 hours ago, SigweardStoneFist said:

somehow I was able to fix it by putting another for loop into it, may be a python bug or so?

but there isn't a goto loop.

Without knowing what the source data looks like it's impossible to say why you had an infinite loop, though i would guess that one of the variables was being changed durring execution.  Thisis possibl eif you are using python 2.x since it supports object orriented programing but does not enforce it. 

In other words SCOPE BABAY (and that's a feature - sadly)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...