python socket GET

前端 未结 6 1413
醉酒成梦
醉酒成梦 2020-12-09 20:20

From the other posts on stack overflow this should be working

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)                 

s.connec         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 20:36

    Sorry to waste everyone's time. I just found this solution here on Stack Overflow (just took some rewording in my Google search to find)

    import socket
    request = b"GET / HTTP/1.1\nHost: www.cnn.com\n\n"
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("cnn.com", 80))
    s.send(request)
    result = s.recv(10000)
    while (len(result) > 0):
        print(result)
        result = s.recv(10000)
    

    And all of the answers were right as well about the ending \r\n\r\n however those returned 301 statuses. This solution seems to follow the redirect somehow? Anyways, this solutions worked for me

提交回复
热议问题