Jan-24-2021, 03:40 AM
Hi All,
The below code works exactly how I want it to work for 'title' but just not working at all for 'address'.
All I want is the Title and Address elements in string format, address works if I don't insert the .string line but just gives all HTML. Please help.
The below code works exactly how I want it to work for 'title' but just not working at all for 'address'.
path = "C:\\Users\\mpeter\\Downloads\\lksd\\" titleList = [] for infile in glob.glob(os.path.join(path, "*.html")): markup = (infile) soup = BeautifulSoup(open(markup, "r").read(), 'lxml') title = soup.find_all("title") title = soup.title.string titleList.append(title) streetAddressList = [] for infile in glob.glob(os.path.join(path, "*.html")): markup = (infile) soup = BeautifulSoup(open(markup, "r").read(), 'lxml') address = soup.find_all("address", class_={"styles_address__zrPvy"}) address = soup.address.string streetAddressList.append(address) with open('output2.csv', 'w') as myfile: writer = csv.writer(myfile) writer.writerows((titleList, streetAddressList))Here is the HTML for the address element.
[<address class="styles_address__zrPvy"><svg class="styles_addressIcon__3Pu3L" height="42" viewbox="0 0 32 42" width="32" xmlns="http://www.w3.org/2000/svg"><path d="M14.381 41.153C2.462 23.873.25 22.1.25 15.75.25 7.051 7.301 0 16 0s15.75 7.051 15.75 15.75c0 6.35-2.212 8.124-14.131 25.403a1.97 1.97 0 01-3.238 0zM16 22.313a6.562 6.562 0 100-13.125 6.562 6.562 0 000 13.124z"></path></svg>Level 1 44 Market Street<!-- -->, <!-- -->Sydney</address>]
All I want is the Title and Address elements in string format, address works if I don't insert the .string line but just gives all HTML. Please help.