我在Python中使用urllib.urlretrieve
下載網站。儘管有些網站似乎不希望我下載它們,除非它們在自己的網站上有適當的推薦人。有沒有人知道我可以在Python的庫或外部庫中設置引用鏈接的方式。在Python中設置引用URL urllib.urlretrieve
6
A
回答
11
import urllib2
req = urllib2.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
r = urllib2.urlopen(req)
3
3
還通過使用urllib2
與build_opener
你可以這樣做:
import urllib2
opener = urllib2.build_opener()
opener.addheaders = [('Referer', 'http://www.python.org/')]
opener.open('http://www.example.com/')
相關問題
- 1. Python urllib.urlretrieve和用戶代理
- 2. urllib.urlretrieve文件python 3.3
- 3. Python urllib.urlretrieve異常處理
- 4. 忽略異常urllib.urlretrieve()在Python 2.7.2
- 5. 在字典中設置索引Python
- 6. 檢查`urllib.urlretrieve(url,file_name)`完成狀態
- 7. urllib.urlretrieve失敗
- 8. 在硒中設置引用
- 9. urllib.urlretrieve()無法下載文件
- 10. 在Apex類中引用遠程站點設置URL?
- 11. 速度的urllib.urlretrieve與urllib.urlopen
- 12. 如何在Python 3中實現等效的urllib.urlretrieve?
- 13. 使用Python下載URL中未明確引用的文檔
- 14. 在Python字典中引用和設置變量
- 15. 在Google應用引擎中設置cron作業python
- 16. urllib.urlretrieve下載空zip文件
- 17. 使用URL在CardView中設置圖像
- 18. 位置索引在python中?
- 19. 用urllib.urlretrieve()保存圖像
- 20. urllib.urlretrieve在磁盤上創建
- 21. 設置在Python
- 22. 在SQL Server 2008中設置引用表
- 23. 在msbuild中未設置項目引用
- 24. URL url = getClass()。getResource(「」)引用的位置?
- 25. 在sourceforge中設置python
- 26. 在vim中設置python virtualenv
- 27. 在Python中設置數據
- 28. 在Python中設置路徑
- 29. 如果不行:使用urllib.urlretrieve時引發EOFError
- 30. 在Python中使用Python設置代理服務器設置(使用InternetSetOption)