【发布时间】:2020-02-16 14:01:49
【问题描述】:
我正在尝试解析来自该站点的一些链接 https://news.ycombinator.com/
我想选择一个特定的表
document.querySelector("#hnmain > tbody > tr:nth-child(3) > td > table")
我知道 bs4 有 css 选择器限制。但问题是我什至无法选择像#hnmain > tbody 和soup.select('#hnmain > tbody') 这样简单,因为它返回empty
使用下面的代码,我无法解析 tbody,而我使用 js(截图)
from bs4 import BeautifulSoup
import requests
print("-"*100)
print("Hackernews parser")
print("-"*100)
url="https://news.ycombinator.com/"
res=requests.get(url)
html=res.content
soup=BeautifulSoup(html)
table=soup.select('#hnmain > tbody')
print(table)
输出:
soup=BeautifulSoup(html)
[]
【问题讨论】:
标签: python web-scraping beautifulsoup python-3.7