【发布时间】:2021-11-12 12:53:11
【问题描述】:
我想从这个网站上获取某个博彩公司的开盘赔率:https://www.betexplorer.com/match-odds/4YWZmAJt/1/1x2/ 所以我有这个功能:
def get_odds(ids):
for id in ids:
url = f'https://www.betexplorer.com{id}'
matchup = url.split('/')[6]
match_id = url.split('/')[7] # <-- this is the last part of URL
api_url = "https://www.betexplorer.com/match-odds/{}/1/1x2/".format(match_id)
headers = {"Referer": "https://www.betexplorer.com",
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'}
s = requests.Session()
s.headers.update(headers)
response = s.get(api_url, headers=headers)
soup = BeautifulSoup(response.text,'html.parser')
print(soup)
ids 是一个list,带有这种字符串
ids=['/soccer/argentina/primera-division-2016/gimnasia-l-p-colon-santa-fe/4YWZmAJt/']
我想以博彩公司的名义find并刮掉他的data-opening-odd
【问题讨论】:
标签: python web-scraping beautifulsoup python-requests