简体   繁体   English

从Python中的URL获取HTML

[英]Fetch HTML From URL in Python

I am trying to read the HTML contents of a URL with Python . 我正在尝试使用Python读取URLHTML内容。 To fetch the HTML contents of a URL , would I use the module wget , urllib or a different module entirely? 要获取URLHTML内容,我是否完全使用模块wgeturllib或其他模块?

After Answers: I will use the urllib module since that comes with the default Python 2.7 build, and I can't download external modules from this computer. 答案之后:我将使用urllib模块,因为它是默认的Python 2.7版本附带的,并且我无法从此计算机上下载外部模块。

List of Modules That Fetch URL Contents: 提取URL内容的模块列表:

Wget
Beautiful Soup
Urllib
Requests

Here is a sample to get you started with requests : 这是一个示例,可帮助您开始处理requests

import requests

resp = requests.get('http://httpbin.org/get')
if resp.ok:
    print (resp.text)
else:
    print ("Boo! {}".format(resp.status_code))
    print (resp.text)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM