相关文章推荐
小眼睛的热带鱼  ·  Python equivalent of ...·  2 周前    · 
俊逸的火锅  ·  Python 控制台 — Blender ...·  2 周前    · 
健身的抽屉  ·  在 Google Cloud 上使用 ...·  2 周前    · 
直爽的黑框眼镜  ·  Difference between ...·  2 周前    · 
性感的毛豆  ·  通过SWIG实现在Python中调用C++代 ...·  1 周前    · 
爱旅游的帽子  ·  《和平精英》携手众乐互娱 ...·  3 月前    · 
可爱的勺子  ·  介绍 Python 线程及其实现·  10 月前    · 
成熟的毛衣  ·  益年养老连锁-新闻资讯-益年养老官方网站·  11 月前    · 
个性的大海  ·  数独解算器 - Sudoku.com 上的谜题解答·  12 月前    · 
一直单身的麻辣香锅  ·  2023年日本新车销量增长13.8% ...·  1 年前    · 
Code  ›  Python equivalent of PHP's file_get_contents on websites (NOT LOCAL FILES) · GitHub
python
https://gist.github.com/TwiN/8e8f928e5b0431e96b60d2caca40556d
小眼睛的热带鱼
2 周前
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Show hidden characters

Updated for Python 3.*:

# some packages were renamed in Python 3
import urllib.request as urllib2
import http.cookiejar as cookielib
def file_get_contents(url):
    url = str(url).replace(" ", "+") # just in case, no space in url
    hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
           'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
           'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
           'Accept-Encoding': 'none',
           'Accept-Language': 'en-US,en;q=0.8',
           'Connection': 'keep-alive'}
    req = urllib2.Request(url, headers=hdr)
        page = urllib2.urlopen(req)
        return page.read()
    except urllib2.HTTPError as e:
        print(e.fp.read())
    return ''
 
推荐文章
小眼睛的热带鱼  ·  Python equivalent of PHP's file_get_contents on websites (NOT LOCAL FILES) · GitHub
2 周前
俊逸的火锅  ·  Python 控制台 — Blender Manual
2 周前
健身的抽屉  ·  在 Google Cloud 上使用 Machine Learning API:实验室挑战赛 | Google Skills
2 周前
直爽的黑框眼镜  ·  Difference between Auto_now_add and Auto_now in Django - GeeksforGeeks
2 周前
性感的毛豆  ·  通过SWIG实现在Python中调用C++代码 – My Home
1 周前
爱旅游的帽子  ·  《和平精英》携手众乐互娱 组建“百万精英计划”-和平精英-官方网站-腾讯游戏
3 月前
可爱的勺子  ·  介绍 Python 线程及其实现
10 月前
成熟的毛衣  ·  益年养老连锁-新闻资讯-益年养老官方网站
11 月前
个性的大海  ·  数独解算器 - Sudoku.com 上的谜题解答
12 月前
一直单身的麻辣香锅  ·  2023年日本新车销量增长13.8% 5年来首次增长_中国经济网――国家经济门户
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号