【问题标题】:Python Webscraper - AttributeError: 'HTTPResponse' object has no attribute 'open'Python Webscraper - AttributeError:“HTTPResponse”对象没有属性“打开”
【发布时间】:2018-10-27 01:56:05
【问题描述】:

我是 python 新手,正在尝试编写一个从 coinbase 抓取加密货币价格的机器人。

import bs4
from bs4 import BeautifulSoup
from urllib.request import urlopen as uReq

my_url = 'https://www.coinbase.com/'
uClient = uReq(my_url)

page_html = uClient.open()
uClient.close()

这是我目前所拥有的。任何建议或更好的方法来实现我正在做的事情将不胜感激。任何解释也会有所帮助。我一直在关注 youtube 视频来做到这一点,但我不确定我是否真的“明白了”。提前致谢!

【问题讨论】:

  • 在 google 上进行一些搜索以了解如何执行此操作,然后返回此处针对您可能遇到的问题提出具体问题

标签: html python-3.x web-scraping


【解决方案1】:

来自文档https://docs.python.org/3/howto/urllib2.html#fetching-urls

import urllib.request
with urllib.request.urlopen('http://python.org/') as response:
   html = response.read()

或者只是改变

page_html = uClient.open()

page_html = uClient.read()

【讨论】:

    猜你喜欢
    • 2016-09-19
    • 1970-01-01
    • 2022-01-14
    • 2020-04-14
    • 2021-12-27
    • 2020-02-12
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多