BeautifulSoup 'markup' is not defined

Following this documentation, I have done everything correctly: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser

Yet, I am getting the error of 'markup' not defined when running my code. The URL is just for an example of the error.

Code:

import requests
from bs4 import BeautifulSoup
from lxml import etree

URL = 'https://www.theverge.com/rss/index.xml'
page = requests.get(URL)

soup = BeautifulSoup(markup, "lxml")


output = soup

print(output)

Error:

import requests...

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
e:\Dev\python\rss_scrape.py in 
      7 page = requests.get(URL)
      8 
----> 9 soup = BeautifulSoup(markup, "lxml")
      10 
     11 

NameError: name 'markup' is not defined

I'm not sure what the issue is here? I have lxml installed as well, so I'm totally lost. Thanks for any help on this.

1 answer

  • answered 2021-02-22 22:38 Hitesh Mishra

    # try this once
    import requests
    from bs4 import BeautifulSoup
    response = requests.get('https://www.theverge.com/rss/index.xml')
    soup = BeautifulSoup(response.text)
    print(soup)