【发布时间】:2021-11-20 06:18:31
【问题描述】:
我之前使用 BeautifulSoup4 在网页中提取了一些信息:https://www.peakbagger.com/list.aspx?lid=5651
我得到了一个href列表:
from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
url = 'https://www.peakbagger.com/list.aspx?lid=5651'
html = urlopen(url)
soup = BeautifulSoup(html, 'html.parser')
a= soup.select("a:nth-of-type(1)")
a
但我只想要链接以“peak.aspx?pid=10...”开头的那个
如何只打印出带有 'peak.aspx?pid=10...' 的那些,我需要使用循环还是拆分它?
谢谢。
【问题讨论】:
-
if 'peak.aspx?pid=10...' in url: <something>...?
标签: python web beautifulsoup hyperlink