【问题标题】:I want to scrape this 400 from a class as shown in the picture, but it's returning none. Any solutions?如图所示,我想从一个类中刮掉这 400 个,但它没有返回。有什么解决办法吗?
【发布时间】:2026-01-10 07:55:01
【问题描述】:

这是我要从中获取文本的课程的屏幕截图。Class picture

我的代码

     r = requests.get("https://www.amazon.ae/sbbn=12303875031&rh=n%3A12303875031%2Cp_n_prime_domestic%3A20642115031&dc&qid=1616415023&rnid=20642114031&ref=lp_12303875031_nr_p_n_prime_domestic_0", headers=headers)
     soup =  BeautifulSoup(r.text, 'html.parser')
     b=soup.find("li",{"class":"a-disabled"})
     print(b)

输出: code ouput

网站链接:https://www.amazon.ae/s?i=fashion&bbn=11995844031&rh=n%3A11995844031%2Cp_n_prime_domestic%3A20642115031&dc&page=11&qid=1616522805&rnid=20642114031&ref=sr_pg_11

【问题讨论】:

  • 代码中的链接会产生 404 错误。确保 URL 在您的浏览器中有效,然后养成在发出请求后检查 HTTP 状态代码的习惯。它通常应该是 200,除非您使用 API。

标签: python flask web-scraping beautifulsoup python-requests


【解决方案1】:

首先确保您确实拥有页面内容,即print r.text or r.content,以确认您拥有页面内容。

不确定您使用的是什么版本的 beautifulsoup,但您也可以尝试语法

company_elem = job_elem.find('div', class_='company')

参考这个documentation

【讨论】:

    最近更新 更多