Python Forum
Unable to convert browser generated xml to parse in BeautifulSoup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to convert browser generated xml to parse in BeautifulSoup
#1
I'm trying to read the below xml generated in a browser using Beautifulsoup:

<?xml version='1.0' encoding='UTF-8'?><IM415 xmlns="http://www.ros.ie/schemas/customs/IM415">
<Declaration>
<MsgType>H1</MsgType>
<DeclarationType_1_1>IM</DeclarationType_1_1>
<AdditionalDeclarationType_1_2>A</AdditionalDeclarationType_1_2>
<LRN_2_5>NIK243186_16KAkj</LRN_2_5>
<ValuationInformation>
<InvoiceCurrency_4_10>EUR</InvoiceCurrency_4_10>
<InvoiceAmount_4_11>5000</InvoiceAmount_4_11>
<InternalCurrency_4_12>EUR</InternalCurrency_4_12>
</ValuationInformation>
<GoodsInformation>
<GrossMass_6_5>300</GrossMass_6_5>
<TotalPackageNumber_6_18>15</TotalPackageNumber_6_18>
</GoodsInformation>


My code is below:
    response = requests.get(driver.current_url)
    print(response)
    soup = BeautifulSoup(response.content, 'lxml-xml')
    print(soup)

    # Save to disk
    with open('test.xml', 'w') as fp:
        fp.write(soup.prettify())
Error as below:

MarkupResemblesLocatorWarning: The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup.
soup = BeautifulSoup(response.content, 'lxml-xml')
<?xml version="1.0" encoding="utf-8"?>



Please help to convert the browser generated xml to be read by BeautifulSoup and get rid of the Markup error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Browser won't parse text from yaml loaded into Jinja SpongeB0B 1 995 Jul-07-2022, 09:37 PM
Last Post: SpongeB0B
  Selenium Parsing (unable to Parse page after loading) oneclick 7 6,033 Oct-30-2020, 08:13 PM
Last Post: tomalex
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,556 Aug-04-2019, 11:10 AM
Last Post: pjn4
  webdriver.remote to connect back existing browser without open new browser? gahhon 6 6,786 Feb-26-2019, 03:53 PM
Last Post: gahhon
  Unable to convert XML to JSON priyanka 1 3,753 Jun-29-2018, 09:23 AM
Last Post: snippsat
  Unable to fetch product url using BeautifulSoup with Python3.6 PrateekG 6 4,247 Jun-05-2018, 05:49 PM
Last Post: PrateekG
  How to use BeautifulSoup to parse google search results DevinGP 16 21,383 Dec-22-2017, 10:23 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020