簡體   English   中英

Python requests 模塊適用於我的 Windows 筆記本電腦,但不適用於 AWS

[英]Python requests module works on my Windows laptop but not on AWS

我是關於 python 的新手,所以如果我錯過了一些基礎知識,我很抱歉。 我有一個關於從網站獲取信息的代碼,並且腳本在我的筆記本電腦上的 vscode 上工作,但是當我嘗試使用相同負載的相同代碼時,它在 AWS ubuntu 和 windows 虛擬計算機上不起作用。 這是代碼:

url_arama = "https://www.sahibinden.com/otomobil/benzin,benzin-lpg/manuel/sahibinden?a4_max=250000&sorting=date_desc&a8=62068&viewType=Classic&a5_min=2004&price_min=25000&price_max=55000"
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}

page = requests.get(url_arama, headers=headers).text
soup = BeautifulSoup(page, "html.parser")    

response = page.json()
print(response)

並且是 output:

Traceback (most recent call last):
  File "c:\Users\Administrator\Desktop\SahibindenBot\aaa.py", line 26, in <module>
    sahibinden()
  File "c:\Users\Administrator\Desktop\SahibindenBot\aaa.py", line 24, in sahibinden
    response = page.json()
AttributeError: 'str' object has no attribute 'json'

我試圖聯系谷歌它可以工作,但你的網站不工作為什么會這樣?

AttributeError: 'str' object 沒有屬性 'json'

嘗試這個:

import json

response = json.loads(page)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM