All of code is inside the function then after
Here a fix an i use BS with lxml as parser,i never use parser in standard library.
return
nothing happens with lines 17-23.Here a fix an i use BS with lxml as parser,i never use parser in standard library.
import requests from bs4 import BeautifulSoup def get_xml(): url="http://energywatch.natgrid.co.uk/EDP-PublicUI/PublicPI/InstantaneousFlowWebService.asmx" headers = {'content-type': 'application/soap+xml; charset=utf-8'} body ="""<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetInstantaneousFlowData xmlns="http://www.NationalGrid.com/EDP/UI/" /> </soap12:Body> </soap12:Envelope>""" response = requests.post(url,data=body,headers=headers) return response.content response = get_xml() soup = BeautifulSoup(response, 'lxml') for item in soup.find_all('EDPObjectName'.lower()): print(item.text)
Output:ALDBROUGH
AVONMOUTH
BACTON BBL
BACTON IC
BACTON PERENCO
BACTON SEAL
BACTON SHELL
BARROW SOUTH
DYNEVOR ARMS
EASINGTON DIMLINGTON
EASINGTON LANGELED
EASINGTON ROUGH ST
.......