这对我学习如何进行低级套接字通信来说是非常困难的一步,但我真的很想学习这个,我遇到了困难,我似乎无法找到正确的方式。
我怎样才能获得所有数据?我已经尝试了多种方法,但只能得到部分响应。
我现在正在尝试的 URL 是:
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