Python urllib urlopen not working

后端 未结 8 1099
甜味超标
甜味超标 2021-01-04 07:29

I am just trying to fetch data from a live web by using the urllib module, so I wrote a simple example

Here is my code:

import urllib

sock = urllib         


        
相关标签:
8条回答
  • 2021-01-04 08:00

    For python 3 the correct way should be:

    import cv2
    import numpy as np
    import urllib.request
    
    req = urllib.request.urlopen('http://answers.opencv.org/upfiles/logo_2.png')
    arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
    img = cv2.imdecode(arr, -1) # 'Load it as it is'
    
    cv2.imshow('image_name', img)
    if cv2.waitKey() & 0xff == 27: quit()
    

    Here you can find the documentation related to urllib.request

    0 讨论(0)
  • 2021-01-04 08:01
    import requests
    import urllib
    
    link = "http://www.somesite.com/details.pl?urn=2344"
    
    f = urllib.request.urlopen(link)
    myfile = f.read()
    
    writeFileObj = open('output.xml', 'wb')
    writeFileObj.write(myfile)
    writeFileObj.close()
    
    0 讨论(0)
提交回复
热议问题