无法从php

我正在使用python库'BS4'进行网络抓取,并将使用php在网页上显示该输出。

使用bs4库抓取网页,我试图运行该python脚本,而不使用python库进行django和flask等Web开发。 我发现有使用“ Laravel”的答案,但由于我不熟悉“ Laravel”,所以无法弄清楚,因此我尝试了“ shell_exec(“ python Script_name.py”)“,但我想我缺少了一些东西。 python文件和php文件位于同一文件夹中。

我尝试过的代码1

<?php 
$command = escapeshellcmd('WebScraperAmazon.py');
$output = shell_exec($command);
echo $output;
?>

我尝试过的代码2

<?php 
    shell_exec('python WebScraperAmazon.py');
?>

这是我的python代码,名为“ WebScraperAmazon.py”

from bs4 import BeautifulSoup
import requests
page_url = "https://www.amazon.in/GeForce-DirectX-192-Bit-Graphics-ZT-P10620A-10M/dp/B07L5FPY3C/ref=sr_1_1?keywords=gtx+1060&qid=1572277711&sr=8-1"
headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/78.0.3904.70 Safari/537.36"}
page = requests.get(page_url,headers=headers)

soup = BeautifulSoup(page.content,'html.parser')

#print(soup.prettify())
title = soup.find(id ="productTitle").get_text()
print(title.strip())

price = soup.find(id="priceblock_ourprice").get_text()
price = price[2:]
price = price.replace(',','')
converted_price = float(price)

print(converted_price)

所需的输出是显示已在网页上抓取的产品的价格和名称。

ZOTAC GeForce GTX 1060 DirectX 12 6GB 192-Bit GDDR5X Graphics Card (ZT-P10620A-10M)
17400
jf5437 回答:无法从php

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3158731.html

大家都在问