[英]How to pass the output of CSS Selector to beautiful soup?
我想抓取一些网页,我使用的是名为“ SelectorGadget”的Chrome扩展程序。 它是一个CSS选择器。 现在以该URL为例: http : //www.www2015.it/documents/proceedings/forms/proceedings.htm CSS选择器为我提供了以下文件列表的输出: tr〜tr + tr td + td a现在,问题所在我无法弄清楚如何将这个输出传递给漂亮的汤。 在以下各行中,.select()无法识别这些选择器!
import requests
page = requests.get("http://www.www2015.it/documents/proceedings/forms/proceedings.htm")
import bs4
soup = bs4.BeautifulSoup(page.content)
soup.select("tr~ tr+ tr td+ td a")
问题是BeautifulSoup
对CSS选择器语法的支持非常有限 。 在您的情况下,与~
或+
并排使用将无法按原样工作。
如果您要匹配此页面上的pdf
链接,则可以使用以下选择器:
soup.select("a[href$=pdf]") # get the links where href ends with "pdf"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.