我现在有个Python爬虫任务,但是请求的url地址用的是wss协议的,搜了很多资料也没头绪,希望有大神指点

葛伦儿 2018-01-30 05:11:14
下面是截图


下面是我尝试写的一些代码:
req = urllib.request.Request('wss://premws-pt12.365lpodds.com/zap/?uid=9446815807967377')
response = urllib.request.urlopen(req)
the_status = response.status
buff = response.read()
the_page = buff.decode("utf8")
response.close()

print(the_status,'----------')
print(the_page)

报的错误是Request不知道wss这个协议。
希望有前辈能给点思路
...全文
2870 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
艾伦26 2019-04-11
  • 打赏
  • 举报
回复
找到解决方案了吗
葛伦儿 2018-02-03
  • 打赏
  • 举报
回复
引用 4 楼 tianfang 的回复:
https://pypi.python.org/pypi/websocket-client 后面有例子
好的,我试试
葛伦儿 2018-02-03
  • 打赏
  • 举报
回复 1
下面是我写的代码:
import websocket

try:
import thread
except ImportError:
import _thread as thread
import time

def on_message(ws, message):
print(message)

def on_error(ws, error):
print(error)

def on_close(ws):
print("### closed ###")

def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
ws.send("Hello %d" % i)
time.sleep(1)
ws.close()
print("thread terminating...")
thread.start_new_thread(run, ())

if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://premws-pt12.365lpodds.com/",
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.on_open = on_open
ws.run_forever()

运行结果:


请问是哪里出了问题呢
葛伦儿 2018-02-03
  • 打赏
  • 举报
回复
可以看一下一楼我发的图,参数Origin应该是:https://mobile.game-365.com 我该怎样修改呢
葛伦儿 2018-01-31
  • 打赏
  • 举报
回复
引用 2 楼 oyljerry 的回复:
wss是websocket的地址。你需要用web socket的client方式请求数据
能举个简单的栗子吗
tianfang 2018-01-31
  • 打赏
  • 举报
回复
https://pypi.python.org/pypi/websocket-client 后面有例子
tianfang 2018-01-31
  • 打赏
  • 举报
回复
https://websockets.readthedocs.io/en/stable/ 适用于python 3.5之后版本
oyljerry 2018-01-30
  • 打赏
  • 举报
回复
wss是websocket的地址。你需要用web socket的client方式请求数据
葛伦儿 2018-01-30
  • 打赏
  • 举报
回复
我想要获取Frames面板里的数据

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧