【问题标题】:AttributeError while attempting to grab table from a website in Python BS尝试从 Python BS 中的网站抓取表格时出现 AttributeError
【发布时间】:2021-10-28 06:39:21
【问题描述】:

我不确定这个 sn-p 是否适用于这个 url 或页面。我尝试在 url 中运行脚本,但出现 AttributeError。

from selenium import webdriver
import requests
from bs4 import BeautifulSoup

browser = webdriver.Chrome('C://Python38/chromedriver')
browser.get("https://poocoin.app/rugcheck/0xe56842ed550ff2794f010738554db45e60730371/top-holders")
url = "https://poocoin.app/rugcheck/0xe56842ed550ff2794f010738554db45e60730371/top-holders"

r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
t = soup.find('table', class_='table table-bordered table-condensed text-small')
trs = t.find('tbody').find_all('tr')
for tr in trs[:10]:
    print(list(tr.stripped_strings))
browser.quit()

当前输出/错误:

    Traceback (most recent call last):
    File "C:/Users/Acer/poocoin.py", line 8, in <module>
    trs = t.find('tbody').find_all('tr')
    AttributeError: 'NoneType' object has no attribute 'find'

【问题讨论】:

    标签: python python-3.x beautifulsoup request


    【解决方案1】:

    因为表格完全依赖于javascript。我还将 HTMLSession 与 BeautifulSoup 一起使用,没有任何错误,也没有输出。如果您更喜欢用scrapy 使用硒,那么我可以为您提供帮助。谢谢

    【讨论】:

    • 该url包含iframe
    • [iframe 图片]: (i.stack.imgur.com/MIxOE.png)
    • “poocoin.app”这个url包含iframe
    • [DOM 中的 iframe]:i.stack.imgur.com/PkRAO.png
    • 其实没什么问题。该 url 显示数据,但数据是从 iframe 和 iframe 元素生成的,要使用此 url 中的 selenium 等自动化工具抓取。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多