网络刮擦标题,设法刮擦链接,但很难使用文件名

发布于 2025-02-08 07:44:21 字数 239 浏览 1 评论 0原文

如何为每个链接刮擦文件的所有名称?我设法刮擦链接,但似乎无法刮擦文件的名称。对于更多的上下文,我使用了Beautifulsoup并找到所有链接。

developer_tool

How can I scrape all the names of the file for each link? I manage to scrape the links but can't seem to scrape the name of the files. For a bit more context I used beautifulsoup and find.all to scrape all the links.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眸中客 2025-02-15 07:44:23

尝试:

import requests
from bs4 import BeautifulSoup

url = "https://m-selig.ae.illinois.edu/ads/coord_database.html"

soup = BeautifulSoup(requests.get(url).content, "html.parser")

for a in soup.select('a[href$=".dat"]'):
    link = a["href"]
    name = a.find_next_sibling(text=True).strip(" \\")
    print("{:<30} {}".format(link, name))

打印:


...
coord/wb13535sm.dat            Woody Blanchard WB135/35 R/C sailplane airfoil
coord/wb140.dat                Woody Blanchard WB140/35/FB R/C sailplane airfoil
coord/whitcomb.dat             NASA/Langley Whitcomb integral supercritical airfoil
coord/ys900.dat                YS900 hyrdofoil (Shen / Eppler)
coord/ys915.dat                YS915 hydrofoil (Shen / Eppler)
coord/ys930.dat                YS930 hydrofoil (Shen / Eppler)

Try:

import requests
from bs4 import BeautifulSoup

url = "https://m-selig.ae.illinois.edu/ads/coord_database.html"

soup = BeautifulSoup(requests.get(url).content, "html.parser")

for a in soup.select('a[href$=".dat"]'):
    link = a["href"]
    name = a.find_next_sibling(text=True).strip(" \\")
    print("{:<30} {}".format(link, name))

Prints:


...
coord/wb13535sm.dat            Woody Blanchard WB135/35 R/C sailplane airfoil
coord/wb140.dat                Woody Blanchard WB140/35/FB R/C sailplane airfoil
coord/whitcomb.dat             NASA/Langley Whitcomb integral supercritical airfoil
coord/ys900.dat                YS900 hyrdofoil (Shen / Eppler)
coord/ys915.dat                YS915 hydrofoil (Shen / Eppler)
coord/ys930.dat                YS930 hydrofoil (Shen / Eppler)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文