import requests
from bs4 import BeautifulSoup
URL = "https://www.fabreminerals.com/search_results.php?LANG=EN&SearchTerms=&submit=Buscar&MineralSpeciment=&Country=&Locality=&PriceRange=&checkbox=enventa&First=0"
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
}
soup = BeautifulSoup(requests.get(URL, headers=headers).text, "lxml")
prices = [
p.getText(strip=True).split("Price:")[-1] for p
in soup.select("table tr td font font")
]
names = [n.getText(strip=True) for n in soup.select("table tr td font a")]
# Filter the lists
names[:] = [" ".join(n.split()) for n in names if not n.startswith("[")]
prices[:] = [p for p in prices if p]
# Print the results
for name, price in zip(names, prices):
print(f"{name}\n{price}")
print("-" * 50)
1条答案
按热度按时间zi8p0yeb1#
试试这个:
输出量: