0

I send my data through get request from python to php website (it's on hosting) and it doesn't work. But when it's on localhost it works

Php:

<?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)

I edit only this string for the site that's on hosting and it doesn't get the GET requests

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

2 Answers2

0

The problem is that your page requires JavaScript for work correctly as shown in the r.text output (i.imgur.com/k5hAEZ0.png).

Now your PHP code doesn't anything other than write the .txt file, there is some HTML/JS code under that?

If not it can be that your hosting provider web server has some filter for "no-js-enabled" HTTP requests? I find it strange that the code stops working only on the hosting server

Another way of solving this problem is by using another python lib that supports JavaScript: Web-scraping JavaScript page with Python

lorenzo
  • 627
  • 8
  • 12
0

Well it was because of the hosting, I only changed it and it works