我正在努力写出自己的预期条件.我需要什么...我有一个iframe.我也有一个图像.我想在图像的scr改变时继续处理.我做了什么:
class url_changed_condition(object):
'''
Checks whether url in iframe has changed or not
'''
def __init__(self, urls):
self._current_url, self._new_url = urls
def __call__(self, ignored):
return self._current_url != self._new_url
Run Code Online (Sandbox Code Playgroud)
后来在我的代码中:
def process_image(self, locator, current_url):
try:
WebDriverWait(self.driver, 10).until(ec.presence_of_element_located((By.TAG_NAME, u"iframe")))
iframe = self.driver.find_element(*locator)
if iframe:
print "Iframe found!"
self.driver.switch_to_frame(iframe)
WebDriverWait(self.driver, 10).until(ec.presence_of_element_located((By.XPATH, u"//div")))
# WebDriverWait(self.driver, 10).until(
# url_changed_condition(
# (current_url, self.driver.find_element(By.XPATH, u"//a/img").get_attribute(u"src"))))
img_url = self.driver.find_element(By.XPATH, u"//a/img").get_attribute(u"src")
print img_url
self.search_dict[self._search_item].append(img_url)
self.driver.switch_to_default_content()
except NoSuchElementException as NSE:
print "iframe not found! {0}".format(NSE.msg)
except:
print "something went wrong" …
Run Code Online (Sandbox Code Playgroud) 我正在python中开发一个可以从多台机器上收集日志的脚本.我正在使用rsync.但是有一个问题.我有多个服务的日志,如下所示:
service1.log
service2.log
service3.log
... and so on
Run Code Online (Sandbox Code Playgroud)
此文件和文件夹的路径在代码中指定.但有时候,当某些日志文件不存在时,我会陷入困境.rsync没有成功完成.
如何跳过源计算机上不存在的文件?
PS我正在使用saltstack来统治机器,所以我打电话给:
__salt__['cmd.retcode']('rsync -a file1 file2...')
Run Code Online (Sandbox Code Playgroud) 我正在编写一个带有类似Python的内置语言的工具.我想在语法中使缩进有意义(因此行开头的制表符和空格将表示命令的嵌套).
做这个的最好方式是什么?
我以前写过递归下降和有限自动机解析器.
关于正则表达式有点棘手的问题.我有这样一个模式的网址:
我怎样才能提取imgurl
价值?
我正在扩展django的用户模型.
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, _(u"User"))
Run Code Online (Sandbox Code Playgroud)
那么,是否可以在用户字段中使用db_index = True和unique = True?然后我需要通过用户名实现搜索.我想到了狮身人面像.有什么想法吗?也许有一些很好的教程链接?TIA
我正试图在我的管理员中显示图像缩略图,但我明白了
<img src="/media/photos/huyase_18638553_orig_.jpeg" width=60 height=60 />
Run Code Online (Sandbox Code Playgroud)
但不是图像.我的模特:
class RentPhoto(models.Model):
'''
Photos for RentItem
Only one photo could be avatar photo
'''
photo = models.ImageField(_('Photo'), upload_to='photos/')
is_avatar = models.BooleanField(_('Avatar'), default=False)
rentitem = models.ForeignKey(RentItem, related_name='photo')
description = models.CharField(_('Description'), max_length=250)
def thumb(self):
if self.photo:
return u'<img src="%s" width=60 height=60 />' % (self.photo.url)
else:
return u'No image file found'
thumb.short_description = _('Thumbnail')
Run Code Online (Sandbox Code Playgroud)
我的admin.py:
class RentPhotoAdmin(admin.ModelAdmin):
fields = ('photo', 'is_avatar', 'rentitem', 'description')
list_display = ('thumb', 'rentitem', 'is_avatar', 'description')
admin.site.register(RentPhoto, RentPhotoAdmin)
Run Code Online (Sandbox Code Playgroud)
我还补充道
(r'^public/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': …
Run Code Online (Sandbox Code Playgroud)