【问题标题】:Get the latest XML file from a HTTPS从 HTTPS 获取最新的 XML 文件
【发布时间】:2017-09-26 23:12:47
【问题描述】:

我在下面的 HTTPS URL 上有一系列 XML 文件。我需要从 URL 中获取最新的 XML 文件。

我试图修改这段代码,但不起作用。请帮忙。

from bs4 import BeautifulSoup
import urllib.request
import requests

url = 'https://www.oasis.oati.com/cgi-bin/webplus.dll?script=/woa/woa-planned-outages-report.html&Provider=MISO'
response = requests.get(url, verify=False)
#html = urllib.request.urlopen(url,verify=False)
soup = BeautifulSoup(response)

我想 beautifulsoup 不会读取响应对象。如果我使用 urlopen 函数,它会抛出 SSL 错误。

【问题讨论】:

    标签: python https beautifulsoup request


    【解决方案1】:

    BeautifulSoup 无法直接理解 requestsResponse 实例 - 获取 .content 并将其传递给“soup”进行解析:

    soup = BeautifulSoup(response.content, "html.parser")  # you can also use "lxml" or "html5lib" instead of "html.parser"
    

    BeautifulSoup 也能理解“类文件”对象 - 这意味着,一旦您发现 SSL 错误问题,您就可以这样做:

    data = urllib.request.urlopen(url)
    soup = BeautifulSoup(data, "html.parser")
    

    【讨论】:

      【解决方案2】:

      我一开始没有正确地提出我的问题。但是在进一步研究之后,我发现我真的是在尝试提取引用的 url 标签中的所有 URL。有了 Beautiful Soup 的更多背景知识,我会使用 soup.find_all('a')。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-15
        相关资源
        最近更新 更多