python的Get请求不会在php上发送

2024-10-01 19:32:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过get请求将数据从python发送到php网站(它是托管的),但它不起作用。但是当它在localhost上时,它就工作了

菲律宾比索:

<?php
$req_dump = print_r($_REQUEST, true);
$fp = file_put_contents('text.txt', $req_dump, FILE_APPEND);
 ?>

Python:

import requests

while True:
    theWeight = input("Enter ")
    r = requests.get('http://localhost:81/index.php', params={'weight': theWeight})
    print(r.url)

我只为托管的站点编辑这个字符串,它没有得到get请求

r = requests.get('http://example.com/index.php', params={'weight': theWeight})

Tags: 数据localhosthttpgetindex网站paramsrequests
2条回答

问题是页面需要JavaScript才能正常工作,如r.text输出(i。imgur.com/k5hAEZ0.png)。你知道吗

现在你的PHP代码除了写.txt文件外什么都没有,下面有一些HTML/JS代码?你知道吗

如果不是的话,可能是你的主机提供商web服务器有一些过滤器“没有启用js”的HTTP请求?我觉得很奇怪,代码只在宿主服务器上停止工作

解决这个问题的另一种方法是使用另一个支持JavaScript的python库:Web-scraping JavaScript page with Python

嗯,是因为主机,我只是改变了它,它的工作

相关问题 更多 >

    热门问题