【问题标题】:Extract all the text from a special type of URL using Python使用 Python 从特殊类型的 URL 中提取所有文本
【发布时间】:2020-10-11 19:43:21
【问题描述】:

我正在尝试从一些 SEC 文件中提取所有文本及其 URL。在遇到某些特殊类型的 URL(似乎与 XBRL 相关)之前,我可以完成大多数 URL 的工作。

url_1 我的代码有效: https://www.sec.gov/Archives/edgar/data/1044378/000156459020025525/bioc-10q_20200331.htm

url_2 我的代码不起作用: https://www.sec.gov/ix?doc=/Archives/edgar/data/1002590/000156459020020844/sgu-10q_20200331.htm

这是我的代码:

with urllib.request.urlopen(url) as url:
    html = url.read()
soup = BeautifulSoup(html, "html.parser")
for table in soup.find_all("table"):
    table.decompose()
for script in soup(["script", "style"]):
    script.extract()  
text = soup.get_text()
print (text)

我是 Python 新手,通过一些 youtube 视频了解到这一点,有人可以帮助我了解如何提取 url_2 的所有文本。

谢谢

【问题讨论】:

    标签: python text-extraction xbrl


    【解决方案1】:

    你说得对,url_2 是一个 iXBRL 链接。幸运的是,普通香草文件的链接就隐藏在那里。

    试试这个:

    url_2 = "https://www.sec.gov/ix?doc=/Archives/edgar/data/1002590/000156459020020844/sgu-10q_20200331.htm"
    url_3=url.replace('ix?doc=/','')
    url_3
    

    输出:

    'https://www.sec.gov/Archives/edgar/data/1002590/000156459020020844/sgu-10q_20200331.htm'
    

    只需将其用作您的目标网址。

    【讨论】:

    • 您也可以将其作为 if 语句,这样它会自动检查您要查找的所有链接:if( 'ix?doc=/' in url)
    • @user12167490 如果我们完成了,请不要忘记接受答案。
    猜你喜欢
    • 2015-08-13
    • 2018-01-22
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    相关资源
    最近更新 更多