我声明了一个变量:
url = baseUrl + urlParam(pair[1].value, conditionMapping[pair[0].value])
其中:
baseUrl = 'http://www.ebay.com/sch/i.html?'
conditionMapping = {'New': '1000', 'New Other': '1000', 'Used': '12'}
def urlParam(product, condition):
return urlencode({'_from':'R40',
'_sacat':'0',
'_nkw':product,
'LH_Complete':'1',
'LH_Sold':'1',
'rt':'nc',
'_sop':'3',
'LH_BIN':'1',
'LH_ItemCondition' : condition})
和pair[0]
和pair[1]
是使用openpyxl从电子表格的单元格中获取的值。你知道吗
这将导致程序生成如下URL:
我现在想做的是,每当对其中一个URL的请求失败时,我都希望能够对URL进行“反向工程”,以找出该URL的对[0]和对[1](产品条件和产品名称)的值。已知url
变量是如何构造的,是否可以这样做?Alternativley,有没有更好的方法来设置我的变量(和/或其他输入)来促进这一点?你知道吗
您可以在处理URL的函数中进行URL处理,如果失败,可以使用
try/catch
块返回这些值。例如:或者(首选方法)捕获特定的异常,并让其他人引发错误:
相关问题 更多 >
编程相关推荐