处理url链接参数技巧(待补充)

urlencode把字典中的键值以等号连接,不同的键值以&连接

from urllib.parse import urlencode

start_urls = 'http://images.so.com/'
data = {'ch': 'beauty', 'listtype': 'new'}
for page in range(1, 10):
    data['sn'] = page * 30
    print(data)
    # urlencode把字典中的键值以等号连接,不同的键值以&连接
    params = urlencode(data) # {'ch': 'beauty', 'listtype': 'new', 'sn': 270}
    print('--------分割线---------')
    print(start_urls+params) # ch=beauty&listtype=new&sn=270

posted @ 2021-09-24 09:36  索匣  阅读(79)  评论(0编辑  收藏  举报