这对我来说是非常艰难的一步,我学习如何做低级套接字通信,但我真的很想学习这一点,我来到了一堵墙,我似乎没有能够找到适当的方式。Python sock.recv没有从页面获取所有数据
我怎样才能得到所有的数据?我已经尝试了很多东西,我只是能够得到部分回应。
我想现在的网址是:
http://steamcommunity.com/market/search/render/?query=&start=0&count=100&search_descriptions=0&sort_column=price&sort_dir=asc&appid=730&category_730_ItemSet%5B%5D=any&category_730_ProPlayer%5B%5D=any&category_730_TournamentTeam%5B%5D=any&category_730_Weapon%5B%5D=any&category_730_Rarity%5B%5D=tag_Rarity_Ancient_Weapon
研究后,我尝试过这种方式,但仍然无法打印上面的完整JSON页面,任何事情我做错了吗?
sock.send(request)
response = ""
first = True
length = 0
while True:
partialResponse = sock.recv(65536)
if len(partialResponse) != 0:
#print("all %s" % partialResponse)
# Extract content length from the first chunk
if first:
startPosition = partialResponse.find("Content-Length")
if startPosition != -1:
endPosition = partialResponse.find("\r\n", startPosition+1)
length = int(partialResponse[startPosition:endPosition].split(" ")[1])
first = False
# add current chunk to entire content
response += partialResponse
# remove chunksize from chunck
startPosition = response.find("\n0000")
if startPosition != -1:
endPosition = response.find("\n", startPosition+1)
response = response[0:startPosition-1] + response[endPosition+1:]
if len(response[response.find("\r\n\r\n")+2:]) > length:
break
else:
break
print response
如果你想要整个事情,你为什么要求最大64K字节? –
我应该要求的最大值是多少? –
@ryachza以及我已经尝试打印对日志的响应,并且每次与Chrome浏览器上显示的内容相比,响应都会缩短。 –