我有我想要优化的代码,因为它开始增加音量:(。我想创建一个数组并从他那里调用值,而不是像现在这样为每个对象创建代码:
post_data_groups = {'profile': '46', 'clear': 'Remove+Avatar'}
post_data_documents = {'folder1': '30', 'remove': 'Delete+Documents'}
urlAdmin_groups = 'http://site.com/management.php?Category=6&uid=196'
urlModerator_groups = 'http://site.com/management.php?Category=6&uid=197'
..........
然后对于文档:
urlAdmin_documents = 'http://site.com/management.php?Category=3&uid=196'
urlModerator_documents = 'http://site.com/management.php?Category=3&suid=197'
.... and so on
data_groups= urllib.urlencode(post_data_groups)
data_documents= urllib.urlencode(post_data_documents)
然后我这样称呼他们:
response = opener.open(urlAdmin_groups, data_groups)
response = opener.open(urlAdmin_documents, data_documents)
........... and so on
the_page = response.read()
由于只有类别和 uid 更改,我如何在调用它们时进行循环?