Python 3.x 如何从faceit中刮取链接

Python 3.x 如何从faceit中刮取链接,python-3.x,web-scraping,beautifulsoup,Python 3.x,Web Scraping,Beautifulsoup,我试图从faceit房间中刮取代码,这是我尝试过的,但它不起作用。 非常感谢您的帮助 import requests from bs4 import BeautifulSoup r = requests.get('https://www.faceit.com/en/csgo/room/1-8d6729b5-cfeb-4059-8894-3b07e04e76b2') soup = BeautifulSoup(r.content, 'html.parser') extracted_link = so

我试图从faceit房间中刮取代码,这是我尝试过的,但它不起作用。 非常感谢您的帮助

import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.faceit.com/en/csgo/room/1-8d6729b5-cfeb-4059-8894-3b07e04e76b2')
soup = BeautifulSoup(r.content, 'html.parser')
extracted_link = soup.find_all('href', class_='list-unstyled')
print(extracted_link)
示例链接:

提取的示例链接:


示例:

页面的所有内容都是动态加载的,这意味着
BeautifulSoup
不会看到它。因此,在
headless
模式下使用
selenium
webdriver
可能会更好

例如:

import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)

url = "https://www.faceit.com/en/csgo/room/1-8d6729b5-cfeb-4059-8894-3b07e04e76b2"
driver.get(url)
time.sleep(2)
element = driver.find_element_by_css_selector('.match-vs .btn-default')
print(element.get_attribute("href"))
输出:

https://demos-europe-west2.faceit-cdn.net/csgo/f9eadb47-aea5-4672-9499-4f457c7d28bd.dem.gz

您也可以仅使用
请求

import requests as r

room_id = '1-8d6729b5-cfeb-4059-8894-3b07e04e76b2'
link = 'https://api.faceit.com/match/v2/match/'+room_id

res = r.get(link)
data = res.json()
extracted_links = data['payload']['demoURLs']
print(extracted_links)

代码探测它们的
API
,以
JSON
的形式一次获取所有数据,然后提取所需信息。

这是否回答了您的问题@Umairmube没有联系…不幸的是没有。