SigweardStoneFist Posted September 9, 2016 Share Posted September 9, 2016 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 More sharing options...
(PSN)eyepet2002 Posted September 21, 2016 Share Posted September 21, 2016 Have you tried checking the goto functions in the code? There might be a goto after the loop that returns it there. Link to comment Share on other sites More sharing options...
(PSN)eyepet2002 Posted September 21, 2016 Share Posted September 21, 2016 Have you tried checking the goto functions in the code? There might be a goto after the loop that returns it there. Link to comment Share on other sites More sharing options...
(PSN)eyepet2002 Posted September 21, 2016 Share Posted September 21, 2016 Whoops! Doublepost.... Link to comment Share on other sites More sharing options...
SigweardStoneFist Posted September 23, 2016 Author Share Posted September 23, 2016 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. Link to comment Share on other sites More sharing options...
Meliq Posted September 23, 2016 Share Posted September 23, 2016 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 More sharing options...
Recommended Posts