获取网址数组并获取数据

时间:2019-09-27 10:04:39

标签: javascript reactjs

我有一组网址,并且我试图获取并显示列表中每个特定网站的状态。对最佳反应方法有什么想法吗?

const URL = [
  {
    name: 'site1',
    url: 'https://something'
  },
  {
    name: 'site2',
    url: 'https://something'
  },
  {
    name: 'site3',
    url: 'https://something'
  }

]

2 个答案:

答案 0 :(得分:-1)

请使用Promises.all.Promise.all()方法返回一个Promise,当作为可迭代对象传递的所有promise已解决或当可迭代对象不包含promise时,将解决该问题

import requests
from bs4 import BeautifulSoup
urls = ['https://e-mehkeme.gov.az/Public/Cases?page=1',
        'https://e-mehkeme.gov.az/Public/Cases?page=2'
        ]

target_url="https://e-mehkeme.gov.az/Public/CaseDetail?caseId={}"

for url in urls:
    response = requests.get(url)
    soup = BeautifulSoup(response.content, "html.parser")

    for caseid in soup.select('input.casedetail'):
        #print(caseid['value'])
        soup1=BeautifulSoup(requests.get(target_url.format(caseid['value'])).content,'html.parser')
        print(soup1.select_one("td").text)

答案 1 :(得分:-1)

您只需要使用map运算符进行列表遍历,以下是stackbliz示例,可能会对您有所帮助。 https://stackblitz.com/edit/array-map-bjaytm?file=index.js