gpt4 book ai didi

python - findall 错误 - NoneType' 对象没有属性 'findall'

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:29 27 4
gpt4 key购买 nike

我不断收到错误“缺少 1 个必需的位置参数:'section_url'”

每次我尝试使用 findall 时都会收到此错误。

刚开始学习 python,因此我们将不胜感激!

from bs4 import BeautifulSoup
import urllib3


def extract_data():

BASE_URL = "http://www.chicagotribune.com/dining/ct-chicago-rooftops-patios-eat-drink-outdoors-near-me-story.html"

http = urllib3.PoolManager()
r = http.request('GET', 'http://www.chicagotribune.com/dining/ct-chicago-rooftops-patios-eat-drink-outdoors-near-me-story.html')
soup = BeautifulSoup(r.data, 'html.parser')
heading = soup.find("div", "strong")
category_links = [BASE_URL + p.a['href'] for p in heading.findAll('p')]
return category_links
print(soup)


extract_data()

最佳答案

根据已接受答案的答案,我认为这就是您想要的

from bs4 import BeautifulSoup
import urllib3

def extract_data():

BASE_URL = "http://www.chicagotribune.com/dining/ct-chicago-rooftops-patios-eat-drink-outdoors-near-me-story.html"

http = urllib3.PoolManager()
r = http.request('GET', 'http://www.chicagotribune.com/dining/ct-chicago-rooftops-patios-eat-drink-outdoors-near-me-story.html')
soup = BeautifulSoup(r.data, 'html.parser')
heading = soup.select('div strong')
print(heading)
category_links = [BASE_URL + p.a['href'] for p in [i for i, x in enumerate(heading) if x == "p"]]
return category_links


print(extract_data())

关于python - findall 错误 - NoneType' 对象没有属性 'findall',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45317069/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com