【发布时间】:2018-10-10 20:57:01
【问题描述】:
我正在尝试抓取 5 秒后加载内容的网页。 我想使用 lib 请求。 有什么东西可以让请求等待吗?
import requests
from bs4 import BeautifulSoup as soup
from time import sleep
link = 'https://www.off---white.com'
while True:
try:
r = requests.get(link, stream=False, timeout=8)
break
except:
if r.status_code == 404:
print("Client error")
r.raise_for_status()
sleep(1)
page = soup(r.text, "html.parser")
products = page.findAll('article', class_='product')
titles = page.findAll('span', class_='prod-title')[0].text.strip()
images= page.findAll('img', class_="js-scroll-gallery-snap-target")
for product in products:
print(product)
【问题讨论】:
标签: python-3.x web-scraping python-requests