我是noob的定义。我对python几乎一无所知,并且正在寻求帮助。我可以阅读足够的代码来改变变量以适应我的需求,但是当我做一些原始代码不需要的东西...我迷路了。Python - 使脚本循环,直到条件满足,并为每个循环使用不同的代理地址
所以这里是交易,我找到了一个craigslist(CL)标记脚本,最初搜索所有CL网站和标记的帖子,其中包含一个特定的关键字(它被写为标记所有提到scienceology的帖子)。
我改变它只在我的一般区域(15个网站而不是437)搜索CL网站,但它仍然会查找已更改的特定关键字。我想自动标记持续垃圾邮件的人,并且很难排序,因为我在CL上做了很多业务,从邮件中排序。
我想让脚本执行循环,直到它不能再在每个循环之后找到满足标准更改代理服务器的帖子。并在剧本里面放置代理/ IP地址的地方
我期待着您的回复。
这里是改变的代码,我有:
#!/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'
如果你只使用'go',只导入'go':'从twill.commands导入go' – askewchan 2013-02-19 21:17:19
导入错误:没有名为模块去 – 2013-02-19 22:18:10
奇怪:HTTP://斜纹.idyll.org/python-api.html说:'从twill.commands进口去' – askewchan 2013-02-19 22:24:07