我正在使用Python腳本來從Metacritic刮取信息。它適用於大多數電影,但它與Metacritic重定向的電影有關。使用urllib刮取Metacritic以跟蹤重定向
例如,在電影列表中,Metacritic提供了「/ movie/red-in-the-year-of-the-year-of-our-Lord-1983」的url,但是當你點擊該URL時,電影/紅騎-三部曲」。我需要urllib獲取最終URL的HTML。
我正在使用Python腳本來從Metacritic刮取信息。它適用於大多數電影,但它與Metacritic重定向的電影有關。使用urllib刮取Metacritic以跟蹤重定向
例如,在電影列表中,Metacritic提供了「/ movie/red-in-the-year-of-the-year-of-our-Lord-1983」的url,但是當你點擊該URL時,電影/紅騎-三部曲」。我需要urllib獲取最終URL的HTML。
我結束了使用請求模塊。 ()以下是請求的代碼以及保存最終網址的行。
response = requests.get(url)
newUrl = response.url
使用try,
import urllib.request
urllib.request.FancyURLopener().open_http("your url")
我收到AttributeError的:「模塊」對象有在該行 – connor
沒有屬性「要求」 @connor見我的編輯爲你錯過了'import'聲明。 – randomusername
「ImportError:No module named request」我在Python 2.7中,所以它可能沒有那個模塊 – connor
不要忘了接受你自己的答案,以標記問題解決':)' – halfer
我會盡快讓我很快被允許。謝謝 – connor