[英]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.