[英]why did I fail to try the post using requests.post?
我知道這則帖子可能與其他問題重復,但是我已經讀過任何帖子,但沒有得到我想知道的內容
在我問這個之前,我已經閱讀了這篇文章 。
我想放棄這個網站與BeautifulSoup
和requests.post
從網上提交某種形式。
我使用的這個示例代碼:
import requests, json
from bs4 import BeautifulSoup as BS
url = "https://www.resi.co.id"
datas = {
"userForm":{
"id":"80879880999985"
}
}
with requests.Session() as s:
req = s.post(url, data=json.dumps(datas)
if req.ok:
soups = BS(req.text,"html.parser")
print(soups.prettify())
我想我可以看到我想要的輸出,但是我沒有想要的輸出結果,我的錯在哪里? 我只是閱讀並嘗試了來自Google的任何示例,然后從stackoverflow發布了內容,但我沒有得到我想要的任何東西。
非常感謝您的幫助,對我的英語感到抱歉。
不太清楚您想要什么,因為不清楚。 但是,要獲取數據,您需要將其包括在datas
。 此外,請求網址是https://api1.cekresi.co.id/allcnote.php
。 它將返回html / text,而不是json。 然后,您可以使用熊貓來抓取這些表:
import requests
import pandas as pd
from bs4 import BeautifulSoup as BS
url = "https://api1.cekresi.co.id/allcnote.php"
datas = {"id":"070950000307119",
'kurir': 'jne'}
with requests.Session() as s:
req = s.post(url, data=datas)
if req.ok:
tables = pd.read_html(req.text)
for table in tables:
print (table)
print ('\n')
輸出:
0 1 2
0 No Resi : 070950000307119
1 Status : DELIVERED
2 Service : YES19
3 Dikirim tanggal : 2019-02-09
4 Dikirim oleh : JESAND SHOPBEKASI
5 Dikirim ke : EDWINPINANG , TANGERANG
6 JNE Status : DELIVERED
0 ... 2
0 Tanggal ... Keterangan
1 2019-02-09 14:07 ... SHIPMENT RECEIVED BY JNE COUNTER OFFICER AT [B...
2 2019-02-09 17:08 ... SHIPMENT PICKED UP BY JNE COURIER [BEKASI]
3 2019-02-09 17:14 ... RECEIVED AT SORTING CENTER [BEKASI]
4 2019-02-09 19:46 ... PROCESSED AT SORTING CENTER [BEKASI]
5 2019-02-10 03:50 ... RECEIVED AT WAREHOUSE [TANGERANG]
6 2019-02-10 05:33 ... SHIPMENT FORWARDED TO DESTINATION [TANGERANG, ...
7 2019-02-10 12:42 ... RUMAH / KANTOR KOSONG
8 2019-02-10 12:42 ... WITH DELIVERY COURIER [TANGERANG]
9 2019-02-11 10:32 ... WITH DELIVERY COURIER [TANGERANG]
10 2019-02-11 13:40 ... ALAMAT TIDAK LENGKAP / TIDAK D
11 2019-02-11 15:10 ... WITH DELIVERY COURIER [TANGERANG]
12 2019-02-11 15:32 ... DELIVERED TO [EDWIN | 11-02-2019 15:32 | TANGE...
[13 rows x 3 columns]
0 1 2
0 Tanggal Lokasi Keterangan
1 2019-02-09 PINANG , TANGERANG DELIVERED
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.