如何使用Spider获取表中的特定结果

我有网站要抓。我的网页抓取工具包括蜘蛛/抓取工具。首先,我在网站上进行研究,然后搜索第一个结果链接,然后抓取该链接的内容。这很好。 如何获取特定属性的a_tag?

def search(terme):
    url = f'https://www.verif.com/recherche/{terme}/1/ca/d/?ville=null'
    response = requests.get(url,headers = {'User-Agent':'Mozilla/5.0'})
    response.raise_for_status()
    return terme,response.text

def spider(terme):      
    try:
        terme,html = search(terme)
        soup = bs(html,'lxml')
        a_tag = soup.select_one('td.verif_col1 a[href]') 
        if a_tag is None:

            link = ''
        else:
            link = f'https://www.verif.com{a_tag["href"]}' 

    except Exception as e:
        print(e)
        link = '' 
    finally:
        time.sleep(10)
    return link 

此代码仅检索第一个结果,我只想在表中获得与搜索到的术语匹配的结果。

xiaoailiang 回答:如何使用Spider获取表中的特定结果

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3145778.html

大家都在问