【发布时间】:2020-02-18 05:51:10
【问题描述】:
我刚开始编程。 我的任务是将数据从 HTML 页面提取到 Excel。 使用 Python 3.7。 我的问题是,我有一个网站,里面有更多的网址。 在这些网址后面又多了更多的网址。 我需要第三个 url 后面的数据。 我的第一个问题是,我如何指示程序仅从 ul 中选择特定链接,而不是页面上的每个 ul?
from bs4 import BeautifulSoup
import urllib
import requests
import re
page = urllib.request.urlopen("file").read()
soup = BeautifulSoup(page, "html.parser")
打印(soup.prettify())
for link in soup.find_all("a", href=re.compile("katalog_")):
links= link.get("href")
if "katalog" in links:
for link in soup.find_all("a", href=re.compile("alle_")):
links = link.get("href")
打印(soup.get_text())
【问题讨论】:
-
能否请您提供一个您想要完成的小示例?
-
我想打开“Bausteine”中的所有网址,打开后面的链接,然后导出那里给出的数据。
标签: python html python-3.x html-lists