【发布时间】:2014-05-01 11:04:28
【问题描述】:
我试过bs4,但是select方法不行。
我的代码有什么问题?
import requests
import bs4
def main():
r = requests.get("http://nodejs.org/download/")
soup = bs4.BeautifulSoup(r.text)
selector = "div.interior:nth-child(2) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > a:nth-child(1)"
print(soup.select(selector)[0].text)
if __name__ == "__main__":
main()
【问题讨论】:
-
BeautifulSoup 4 似乎从 3 回归,它不支持它应该支持的一些选择器。例如,
h1.a.b与我的<h1 class="a b">不匹配。
标签: python web-scraping beautifulsoup