【发布时间】:2018-11-30 01:34:52
【问题描述】:
我正在尝试使用 BeautifulSoup 从以下网页获取一些信息:
url = 'https://web.archive.org/web/20071001215911/http://finance.rambler.ru'
在我的浏览器 (Chrome) 的帮助下,我复制了所需元素的选择器:
selector = 'body > div.fe_global > table:nth-child(6) > tbody > tr > td:nth-child(2) > table > tbody > tr > td.fe_col-left > div:nth-child(5) > table > tbody'
但是,bs4 不支持 nth-child,因此我将其替换为 nth-of-type:
selector = selector.replace('child', 'of-type')
把它涂在汤上
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
selected_element = soup.select(selector=selector)
print (selected_element)
输出是 []。 我希望得到一些 HTML 代码。 这样回答的原因是什么? 感谢您的帮助。
【问题讨论】:
标签: python parsing beautifulsoup css-selectors