【发布时间】:2021-12-26 03:05:43
【问题描述】:
我想从这个pages 中提取产品href 属性。是否有任何错误或阻塞?
我的代码:
import datetime, re, time, requests
import pandas as pd
import numpy as np
from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter
from bs4 import BeautifulSoup as bs4
url2 = "https://www.vidri.com.sv/catalogo/07040101/Taladros-y-atornilladores-inalambricos.html"
headers = {"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40"}
r2 = requests.get(url2, headers)
soup2 = bs4(r2.content, "lxml", parse_only=None)
products_container = soup2.find("div", class_= "products__container")
for item in products_container.find_all("div", class_= "productCard"):
for sku in item.find_all("a", href = True):
link_list.append(sku["href"])
link_list
【问题讨论】:
标签: python web-scraping beautifulsoup python-requests