2017-09-26 205 views
0

我在下面的HTTPS URL處有一系列XML文件。我需要從URL中獲取最新的XML文件。從HTTPS獲取最新的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錯誤。

回答

0

BeautifulSoup不理解requestsResponse情況下直接 - 搶.content並把它傳遞給‘湯’解析:

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") 
0

我沒有正確地框架我的問題擺在首位。但經過深入研究,我發現我真的試圖提取所引用的url標記中的所有URL。隨着美麗湯的更多背景,我會使用soup.find_all('a')。