请求时返回相同的html页面

时间:2019-05-04 04:39:54

标签: python python-requests

在同一网页中尝试使用不同的网址时,我得到的是相同的html页面 我已经尝试了很多次,但是没有得到预期的结果

import requests
req=requests.get('https://cricbuzz.com')
reqq=requests.get('https://www.cricbuzz.com/cricket-match-highlights/22487/kxip-vs-kkr-52nd-match-indian-premier-league-2019')
print(req.text)
print(reqq.text)

两个print语句都返回相同的html页面,但实际上这不是预期的结果

1 个答案:

答案 0 :(得分:0)

您没有获得相同的页面(或者至少我不了解您的示例)

import requests
from bs4 import BeautifulSoup as bs

soup1 = bs(requests.get('https://cricbuzz.com').content, 'lxml')
soup2 = bs(requests.get('https://www.cricbuzz.com/cricket-match-highlights/22487/kxip-vs-kkr-52nd-match-indian-premier-league-2019').content, 'lxml')

print(soup1.select_one('[rel=canonical]')['href'])
print(soup2.select_one('[rel=canonical]')['href'])

enter image description here

您也可以完成

print(req.text == reqq.text)