Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

python list.remove() not working

So i am creating a proxy scraper and I am trying to remove not working

so all the proxies are scraped and stored in list called proxies I then try open a webpage (this case facebook.com) using the proxy and then I want it to remove if it doesn't work.

The proxy list is map for speed.
Code
def proxyCheck(p):
    global proxies
    try:
        session.get('https://facebook.com', proxies={'https' :p}, timeout=1)
    except:
        print "%s removed" % p
        proxies.remove(p)


print "removing down proxies (%d)" % len(proxies)
p = Pool(cpu_count())
p.map(proxyCheck, proxies[:]) #[:] to make a copy, I read you can't remove as your iterarting
print "using %d" % len(proxies)
but the length stays the same and nothing is removed, i've tried appends to a new list and that doesn't worth either.

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Jul 20, 2017 05:36 AM)vorticalbox Wrote:  So i am creating a proxy scraper and I am trying to remove not working

so all the proxies are scraped and stored in list called proxies I then try open a webpage (this case facebook.com) using the proxy and then I want it to remove if it doesn't work.

The proxy list is map for speed.
Code
def proxyCheck(p):
    global proxies
    try:
        session.get('https://facebook.com', proxies={'https' :p}, timeout=1)
    except:
        print "%s removed" % p
        proxies.remove(p)


print "removing down proxies (%d)" % len(proxies)
p = Pool(cpu_count())
p.map(proxyCheck, proxies[:]) #[:] to make a copy, I read you can't remove as your iterarting
print "using %d" % len(proxies)
but the length stays the same and nothing is removed, i've tried appends to a new list and that doesn't worth either.

try removing the global proxies line
i like python lua js
(Jul 20, 2017 06:05 AM)Riԁdle Wrote:  try removing the global proxies line

That worked but some don't get remove I added a check to see if it is still in the list. I am guessing thats due to access of all the threads?


Just let it run it says "removed" but it still in the list :(


Just to up date i never did solve this but as a work around i saved working proxies to a file and the emptied the array then filled it up from the file and finally deleting the file.

Not the most efficient way to get the job dome but it works.

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
If you posted the full traceback we could maybe offer greater assistance.

P.s. to avoid duplicates and to improve general performance, perhaps consider using sets as opposed to arrays. You could load an existing array into a set using the Set(array) function
(Jul 22, 2017 10:22 AM)icmp Wrote:  If you posted the full traceback we could maybe offer greater assistance.

P.s. to avoid duplicates and to improve general performance, perhaps consider using sets as opposed to arrays. You could load an existing array into a set using the Set(array) function

Under up returning true/false and using compression like in my proxy post.

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by Ineed2learn2eatJul 13, 2017 10:48 AM 3 230 Jul 13, 2017 10:48 AM
Last Post: Ineed2learn2eat
[.NET] by GørillaFeb 28, 2017 07:24 AM 13 451 Feb 28, 2017 07:24 AM
Last Post: Gørilla