如何在一个Python调用中提取多个URL

时间:2019-08-04 16:52:07

标签: python

我正在尝试在同一Python调用中提取多个网站。我无法使其正常工作,并且不得不单独输入每个电话。

我已经尝试执行以下操作:

URL = ['https://sc2replaystats.com/replay/playerStats/10758933/83445': https://sc2replaystats.com/replay/playerStats/10758969/83445]
content = requests.get(URL)

soup = BeautifulSoup(content.text, 'html.parser')

contentTable  = soup.find('table', "table table-striped table-condensed")
rows = contentTable.find_all('span', "blizzard_icons_single") 
print (rows)

这是我当前的代码:

from bs4 import BeautifulSoup # BeautifulSoup is in bs4 package 
import requests

URL = 'https://sc2replaystats.com/replay/playerStats/10758969/83445'
content = requests.get(URL)

soup = BeautifulSoup(content.text, 'html.parser')

contentTable  = soup.find('table', "table table-striped table-condensed")
rows = contentTable.find_all('span', "blizzard_icons_single") 
print (rows)

1 个答案:

答案 0 :(得分:1)

您不能将多个http请求合并为一个。但是,您可以一个接一个地做它们。也许查看listsloops上的python文档。

urls = ['http://example.com', 'http://example.org']
for url in urls:
    content = requests.get(url)
    print(content)