【发布时间】:2018-11-15 09:38:40
【问题描述】:
我正在尝试从以下页面提取 TR 数据: http://www.datasheetcatalog.com/catalog/p1342320.shtml
我正在使用请求和BeautifulSoup。但是,我没有得到所有行(第二个表中只有 12 行而不是 22 行)。有没有人对此有解释(前提是打印 response.content 时有这些行。)?
这是我正在使用的代码:
from bs4 import BeautifulSoup
import requests
session = requests.Session()
url = 'http://www.datasheetcatalog.com/catalog/p1342320.shtml'
response = session.get(url)
soup = BeautifulSoup(response.content,"lxml")
trs= soup.findAll('table')[8].findAll('tr')
print (len(trs))
【问题讨论】:
-
我得到了
22作为print(len(tr2))的输出...你想要的输出是什么? -
奇怪! ...我得到 12 而不是 22
-
@Andersson 你用的是哪个python版本?
-
我使用的是 Python 3.6
-
是的,仍然收到
22
标签: python-3.x beautifulsoup python-requests