下面有一个链接( freepeople+top有+替换一个空格)
https://poshmark.com/search?query=freepeople+top&type=listings&department=Women我这样做是为了查询链接:
search='https://poshmark.com/search?'
brand="freepeople"
style="top"
# & seperates parameters
queryParameters={'query':[brand,style],'type':'listings','department':'Women'}
response=requests.get(search,params=queryParameters)我不明白为什么当我打印(response.text)时,它似乎给了我所有的html,但当我这样做:
MacBook-Air-4:finalproject BCohen$ python3 poshmart.py >/tmp/poshmart.html
MacBook-Air-4:finalproject BCohen$ open /tmp/poshmart.html它不会带我去一个有效的页面
我假设可能我查询了索引搜索(+)错误,但我不知道如何正确地查询它。
发布于 2018-03-30 01:20:20
您可以使用'+'.join([brand,style])将该数组转换为一个字符串,在该字符串中,值与+连接。结果就是你要找的东西:freepeople+top
import requests
search='https://poshmark.com/search?'
brand="freepeople"
style="top"
print('+'.join([brand,style]))
# & seperates parameters
queryParameters={'query':'+'.join([brand,style]),'type':'listings','department':'Women'}
response=requests.get(search,params=queryParameters)
print(response.request.url)输出是
freepeople+top
https://poshmark.com/search?query=freepeople%2Btop&type=listings&department=Women它之所以在第二版中显示为%2B,是因为它是+的urlencoded值。
https://stackoverflow.com/questions/49566866
复制相似问题