urlopen

    2熱度

    2回答

    讓我們考慮一個大文件(〜100MB)。讓我們考慮這個文件是基於行的(一個文本文件,相對較短的行~80個字符)。 如果我使用內置的open()/file()該文件將被加載到lazy manner。 I.E.如果我做aFile.readline()只有一個文件塊將駐留在內存中。 urllib.urlopen()是否做了類似的事情(使用磁盤上的緩存)? urllib.urlopen().readline

    2熱度

    3回答

    我想從下面的代碼中的地址讀取一些utf-8文件。它適用於其中的大部分,但對於某些文件,urllib2(和urllib)無法讀取。 這裏很明顯的答案是第二個文件已損壞,但奇怪的是IE瀏覽器都讀取了它們,而且完全沒有問題。代碼已經在XP和Linux上進行了測試,結果相同。任何消化? import urllib2 #This works: f=urllib2.urlopen("http://www.

    3熱度

    2回答

    這段代碼有什麼問題? >>> from urllib.request import urlopen >>> for line in urlopen("http://google.com/"): print(line.decode("utf-8")) <!doctype html><html><head><meta http-equiv="content-type" conten

    2熱度

    2回答

    我在Python中使用urllib和urllib2來打開和閱讀網頁,但有時,我得到的文本是不可讀的。例如,如果我運行此: import urllib text = urllib.urlopen('http://tagger.steve.museum/steve/object/141913').read() print text 我得到一些不可讀的文本。我看過這些帖子: Gibberish

    1熱度

    2回答

    我想一些文字傳遞給該readability API像這樣: text = 'this reminds me of the Dutch 2001a caravan full of smoky people Auld Lang Syne' # construct Readability Metrics API url request_url = 'http://ipeirotis.appspot.

    2熱度

    1回答

    超時後沒有終止在Python 2.4.4的urlopen調用,我使用urllib2.urlopen()請求資源。發出請求之前,我設置了超時: socket.setdefaulttimeout(10) (Python的這種版本太舊有內置的超時版本的urlopen()) 在大多數情況下,這似乎工作正常。但是,我遇到了一個只能根據請求掛起的服務器。在Chrome瀏覽器中,瀏覽器放棄需要將近5分鐘,然

    0熱度

    1回答

    所以我檢索從一個網站的一些JSON數據,並使用標準的urlopen()從urllib2的: 代碼: url = 'http://api.nytimes.com/svc/politics/v3/us/legislative/congress/senate/votes/2011-12-14/2011-12-14.json?api-key=%s' % (api_key,) print urlopen(

    2熱度

    1回答

    我使用python urllib2.urlopen獲取html內容,我得到一個gziped響應。 我可以設置標題,所以我會得到它不拉鍊? 我的代碼 response = urlopen(url,None , TIMEOUT) html = response.read() # read html print html 爲Tichodroma建議我試試這個 request = Request(

    3熱度

    1回答

    我想使用Python urlopen獲取html網站。 我收到此錯誤: HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop 代碼: from urllib2 import Request request = Request(url) re

    4熱度

    1回答

    我正在使用gevent預執行併發下載。 基於this例子是這樣的代碼: import gevent from gevent import monkey urls = ['https://www.djangoproject.com/','http://www.nytimes.com/','http://www.microsoft.com'] monkey.patch_all() impo