Python 请求。获取不正确的信息

Python 请求。获取不正确的信息,python,Python,我想得到一个网站的几个“页面”,但由于某些原因,正确的url并没有给出预期的结果 我查看了应该使用的url,它工作正常,并尝试使用一些变量更改 for i in range(1,100): MLinks.append("https://#p" + str(i)) for i in range(1,100): x = i-1 MainR = requests.get(MLinks[x]) SMHTree = html.fromstring(MainR.conte

我想得到一个网站的几个“页面”,但由于某些原因,正确的url并没有给出预期的结果

我查看了应该使用的url,它工作正常,并尝试使用一些变量更改

for i in range(1,100):
    MLinks.append("https://#p" + str(i))

for i in range(1,100):
    x = i-1
    MainR = requests.get(MLinks[x])

    SMHTree = html.fromstring(MainR.content)
    MainData = SMHTree.xpath('//@*')
    j=0
    while j <len(MainData):
        if 'somthing' in MainData[j] :
            PLinks.append(MainData[j]) #Links of products
        j=j+1
范围(1100)内的i的
:
MLinks.append(“https://#p”+str(i))
对于范围(1100)内的i:
x=i-1
MainR=requests.get(MLinks[x])
SMHTree=html.fromstring(main.content)
MainData=SMHTree.xpath('/@*'))
j=0

而j我假设您请求的URL如下所示:

https://somehost.com/products/#p1
https://somehost.com/products/#p2
https://somehost.com/products/#p3
...
也就是说,代码的第二行实际上是

MLinks.append("https://somehost.com/products/#p" + str(i))
在执行请求时,服务器从未看到#之后的部分(该部分称为锚定)。因此,服务器只收到100个“”请求,所有请求都给出相同的结果。请参阅此网站的进一步解释:

客户端JavaScript有时使用锚来动态加载页面。这意味着,如果您打开“”并导航到“”,客户端JavaScript将注意到它,并(通常)向其他URL发出请求,以加载第5页上的产品。此其他URL将不会为“”!要了解此URL是什么,请打开浏览器的开发人员工具,查看在导航到其他产品页面时发出的网络请求