我正在尝试对图像选项卡进行网络抓取,以便获得可以使用的链接,这样我就可以直接访问我正在制作的项目的图像。
问题是,每当我尝试编写 "print(soup.find('a' , class_ = 'q qs')) 时,如果没有,它就会给出输出
我遇到的另一个问题是视频和新闻标签等其他标签具有相同的标签但链接不同,那么我该如何区分两者?
图片链接的 HTML 我希望我可以在这里放一个屏幕截图,因为这很难理解。
图像标签
<div class="hdtb-mitem hdtb-imb" aria-selected="false" role="tab"><a class="q qs" href="/search?q=dogs&safe=active&client=safari&rls=en&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiqhrOi06zkAhVFVRUIHeBbATwQ_AUIESgB"><span class="HF9Klc ZYMsjf" style="height:16px;width:16px"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M14 13l4 5H6l4-4 1.79 1.78L14 13zm-6.01-2.99A2 2 0 0 0 8 6a2 2 0 0 0-.01 4.01zM22 5v14a3 3 0 0 1-3 2.99H5c-1.64 0-3-1.36-3-3V5c0-1.64 1.36-3 3-3h14c1.65 0 3 1.36 3 3zm-2.01 0a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h7v-.01h7a1 1 0 0 0 1-1V5z"></path></svg></span>Images</a></div>
图像链接的 HTML
<a class="q qs" href="/search?q=dogs&safe=active&client=safari&rls=en&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiqhrOi06zkAhVFVRUIHeBbATwQ_AUIESgB"><span class="HF9Klc ZYMsjf" style="height:16px;width:16px"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"></path><path d="M14 13l4 5H6l4-4 1.79 1.78L14 13zm-6.01-2.99A2 2 0 0 0 8 6a2 2 0 0 0-.01 4.01zM22 5v14a3 3 0 0 1-3 2.99H5c-1.64 0-3-1.36-3-3V5c0-1.64 1.36-3 3-3h14c1.65 0 3 1.36 3 3zm-2.01 0a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h7v-.01h7a1 1 0 0 0 1-1V5z"></path></svg></span>Images</a>
视频标签
<div class="hdtb-mitem hdtb-imb" aria-selected="false" role="tab"><a class="q qs" href="/search?q=dogs&safe=active&client=safari&rls=en&source=lnms&tbm=vid&sa=X&ved=0ahUKEwiqhrOi06zkAhVFVRUIHeBbATwQ_AUIEigC"><span class="HF9Klc ZYMsjf" style="height:16px;width:16px"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M0 0h24v24H0z" fill="none"></path><path clip-rule="evenodd" d="M10 16.5l6-4.5-6-4.5v9zM5 20h14a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1zm14.5 2H5a3 3 0 0 1-3-3V4.4A2.4 2.4 0 0 1 4.4 2h15.2A2.4 2.4 0 0 1 22 4.4v15.1a2.5 2.5 0 0 1-2.5 2.5z" fill-rule="evenodd"></path></svg></span>Videos</a></div>
视频链接的 HTML
<a class="q qs" href="/search? q=dogs&safe=active&client=safari&rls=en&source=lnms&tbm=vid&sa=X&ved=0ahUKEwiqhrOi06zkAhVFVRUIHeBbATwQ_AUIEigC"><span class="HF9Klc ZYMsjf" style="height:16px;width:16px"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M0 0h24v24H0z" fill="none"></path><path clip-rule="evenodd" d="M10 16.5l6-4.5-6-4.5v9zM5 20h14a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1zm14.5 2H5a3 3 0 0 1-3-3V4.4A2.4 2.4 0 0 1 4.4 2h15.2A2.4 2.4 0 0 1 22 4.4v15.1a2.5 2.5 0 0 1-2.5 2.5z" fill-rule="evenodd"></path></svg></span>Videos</a>
您可以看到图像和视频选项卡的标签是相同的,我只有一个可以检索其中一个,我该怎么做呢,我只想要指向图像选项卡的链接而不是视频选项卡。