类型错误:某些关键字参数意外

问题描述 投票:0回答:1

我正在尝试为页面编写一个解析器。我正在使用 LxmlSoup 库。 所以交易是:

html = requests.get('https://www.mcdonalds.com/ua/uk-ua/eat/fullmenu.html').text
soup = LxmlSoup(html)
urls = soup.find_all('a', class_='cmp-category__item-link')
items = []

for url in urls:
    link = "https://www.mcdonalds.com" + url.get("href")

    item_html = requests.get(link).text
    item_soup = LxmlSoup(item_html)

    item_name = item_soup.find('span', class_='cmp-product-details-main__heading-title').text()And the error is:     

Traceback (most recent call last): File "C:\Users\111\PycharmProjects\pythonProject2\main.py", line 17, in <module> item_name = item_soup.find('span', class_='cmp-product-details-main__heading-title') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\111\PycharmProjects\pythonProject2\.venv\Lib\site-packages\LxmlSoup\LxmlSoup.py", line 25, in find elements = self.findel(tag, **attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: some keyword arguments unexpected 

我只是不知道我应该在这个函数中准确传递什么

python python-3.x parsing beautifulsoup lxml
1个回答
0
投票
html = requests.get('https://www.mcdonalds.com/ua/uk-ua/eat/fullmenu.html').text
soup = LxmlSoup(html)
urls = soup.find_all('a', class_='cmp-category__item-link')
items = []

for url in urls:
    link = "https://www.mcdonalds.com" + url.get("href")

    item_html = requests.get(link).text
    item_soup = LxmlSoup(item_html)

    item_name = item_soup.find('span', class_='cmp-product-details-main__heading-title').text()
© www.soinside.com 2019 - 2024. All rights reserved.