【发布时间】:2021-06-14 00:08:47
【问题描述】:
感谢 stackoverflow 上的许多帖子,我找到了许多接近我的解决方案的方法,但似乎我总是遇到同样的问题。我只得到表格的第一列
目标: This URL这里只有一张桌子,我想刮一下
这是我的代码:
# 1. get the html doc
source = requests.get("www.placeholder.com").text
# 2. get the BeautifulSoup object
soup = bs.BeautifulSoup(source, 'lxml')
# 3. find the table
find_class = soup.table
tbody_1 = find_class.tbody
n = 1
m = 1
for row in tbody_1.find_all('tr'):
for col in row.find_all('td'):
if col == "Tag":
print(col)
print(n)
print(m)
print("Tags will be passed")
pass
else:
if n < 13:
value_list = []
value_list.append(col)
print(col)
print(n)
print(m)
val_dict[m] = value_list
n = n+1
# m = m
else:
value_list = []
value_list.append(col)
print(col)
print(n)
print(m)
val_dict[m+1] = value_list
n = 1
m = m+1
这给了我以下问题: Tags
使用:
value_list.append(col.select('span')[0].get_text())
导致以下问题: First Item。 这里只使用了每行的第一项
灵感来自(答案)尤其是this link
for row in table.find_all('tr'):
for col in row.find_all('td'):
除了我提供的内容之外,我会在需要时编辑帖子。
【问题讨论】:
-
It's scrape not scrap,因为scrap意味着摆脱为no足够长的时间。
-
谢谢,会编辑
-
你想要的输出是什么?整张桌子?
-
是的整张桌子
-
我想我迷失了许多实现它的方法,但不知何故没有把它们做对
标签: python beautifulsoup