微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python bs4 find() return none

如何解决python bs4 find() return none

您好专家!我使用 bs4 find() 函数没有得到任何结果,即使它存在于 html 中。我正在尝试使用 tab_content获取所有 div。我在此链接 https://sofad.qc.ca/index.php?id_product=464&controller=product&id_lang=1 上找到了这个。所以请建议我如何以正确的方式做到这一点。 这是代码

from bs4 import BeautifulSoup as bs
import requests

url = 'https://sofad.qc.ca/index.PHP?id_category=78&controller=category&id_lang=1'
r = requests.get(url)
soup = bs(r.content,'html.parser')
tb = soup.find_all('a',class_='product_img_link')


for item in tb:
    link = item.get('href')
    r = requests.get(link)
    soup = bs(r.content,'lxml')
    try:
        title = soup.find('h1',{'itemprop':'name'}).text
    except:
        title = ''
    try:
        price = soup.find('span',id='our_price_display').text
    except:
        price = ''
    try:
        img = soup.find('img',id='bigpic').get('src')
    except:
        img = ''
    try:
        dv = " ".join(soup.find('div',class_='rte').text.split())
    except:
        dv = ''
    for dvv in soup.find_all('div',class_='tab_content'):
        print(dvv)

解决方法

据我所知,语法是 height: 3px; NOT WITH x AS ( SELECT * FROM (VALUES ('2020-05-17 8:50:24'::timestamp,'2020-05-17 12:12:43'::timestamp,100),('2020-05-22 17:29:19'::timestamp,'2020-05-22 19:44:46'::timestamp,98),('2020-05-06 17:22:51'::timestamp,'2020-05-06 19:11:41'::timestamp,84),('2020-05-06 19:25:15'::timestamp,'2020-05-06 20:35:53'::timestamp,68),('2020-05-06 15:04:52'::timestamp,'2020-05-06 17:05:13'::timestamp,90),('2021-01-11 13:32:45'::timestamp,'2021-01-11 15:57:46'::timestamp,104),('2020-05-26 13:19:05'::timestamp,'2020-05-26 16:05:12'::timestamp,105),('2020-12-05 7:08:31'::timestamp,'2020-12-05 10:22:00'::timestamp,77) ) x (race_start_time,race_end_time,total_money_raised) ) SELECT a.race_start_time,a.race_end_time,a.total_money_raised,SUM(b.total_money_raised) FROM x a JOIN x b ON b.race_start_time BETWEEN a.race_start_time AND dateadd(day,1,a.race_start_time) GROUP BY 1,2,3 ORDER BY 1;

要查找类为 findAllfind_all

div

仅供参考,该页面的 html 树中没有带有 tab_content 类的 div。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。