I'm the definition of a noob. I know next to nothing about python and am looking for help. I can read just enough code to alter variables to suit my wants/needs but I when it comes to doing something the original code didn't call for... I'm lost.
So here is the deal, I found a craigslist(CL) flagging script that originally searched ALL CL sites and flagged posts that contained a specific keyword (it was written to flag all posts that mentioned scientology).
I altered it to only search CL sites in my general area (15 sites instead of 437) but it still looks for specific keywords that have have changed. I want to automatically flag people that continuously spam CL and make it hard to sort through as I do a lot of business on CL from sorting through postings.
What I want the script to do is loop until it can no longer find posts that meet the criteria changing proxy servers after each loop. And a place inside the script where I would put in the proxy/s ip adress
I look forward to your replies.
Here is the altered code I have:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
from twill.commands import * # gives us go()
areas = ['sfbay', 'chico', 'fresno', 'goldcountry', 'humboldt', 'mendocino', 'modesto', 'monterey', 'redding', 'reno', 'sacramento', 'siskiyou', 'stockton', 'yubasutter', 'reno']
def expunge(url, area):
page = urllib.urlopen(url).read() # <-- and v and vv gets you urls of ind. postings
page = page[page.index('<hr>'):].split('\n')[0]
page = [i[:i.index('">')] for i in page.split('href="')[1:-1] if '<font size="-1">' in i]
for u in page:
num = u[u.rfind('/')+1:u.index('.html')] # the number of the posting (like 34235235252)
spam = 'https://post.craigslist.org/flag?flagCode=15&postingID='+num # url for flagging as spam
go(spam) # flag it
print 'Checking ' + str(len(areas)) + ' areas...'
for area in ['http://' + a + '.craigslist.org/' for a in areas]:
ujam = area + 'search/?query=james+"916+821+0590"+&catAbb=hhh'
udre = area + 'search/?query="DRE+%23+01902542+"&catAbb=hhh'
try:
jam = urllib.urlopen(ujam).read()
dre = urllib.urlopen(udre).read()
except:
print 'tl;dr error for ' + area
if 'Found: ' in jam:
print 'Found results for "James 916 821 0590" in ' + area
expunge(ujam, area)
print 'All "James 916 821 0590" listings marked as spam for area'
if 'Found: ' in dre:
print 'Found results for "DRE # 01902542" in ' + area
expunge(udre, area)
print 'All "DRE # 01902542" listings marked as spam for area'