在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python3+beautifulsoup動(dòng)態(tài)數(shù)據(jù)獲取想要的內(nèi)容

python3+beautifulsoup動(dòng)態(tài)數(shù)據(jù)獲取想要的內(nèi)容

想獲取文學(xué)網(wǎng)站一篇文章的章節(jié)點(diǎn)擊量,網(wǎng)站地址:http://www.jjwxc.net/onebook....

想要獲取的動(dòng)態(tài)信息對(duì)應(yīng)的url:http://s8-static.jjwxc.net/ge...

這是我的代碼:

from bs4 import BeautifulSoup
import requests
url = "http://s8-static.jjwxc.net/getnovelclick.php?novelid=3601&jsonpcallback=novelclick"
web_data = requests.get(url)
web_data.encoding = "gzip"
soup = BeautifulSoup(web_data.text, "html.parser")
print(soup)

print 出來(lái)是這樣的:

novelclick({"1":"82686","2":"73363","3":"52320","4":"49171","5":"46838","6":"43687","7":"36339","8":"36067","9":"35917","10":"35570","11":"32912","12":"34357","13":"33653","14":"31370","15":"33803","16":"32647","17":"30681","18":"32163","19":"29455","20":"31213","21":"30199","22":"28536","23":"30041","24":"28862","25":"29439","26":"29469","27":"29378","28":"29678","29":"31427","30":"53411"})

如何去掉前面的novelclick, 使章節(jié)和點(diǎn)擊量排列好,像這樣:
1 82686
2 73363
3 52320
4 49171
.
..

回答
編輯回答
別逞強(qiáng)

突然不給返回?cái)?shù)據(jù)了,只能把正則匹配出來(lái)的東西寫成變量了


import requests
import re
import json

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 \
    (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"
}

url = "http://s8-static.jjwxc.net/getnovelclick.php?novelid=3601&jsonpcall\
back=novelclick"
web_data = requests.get(url, headers=headers)
web_data.encoding = "gzip"
result = web_data.content.decode()
string = re.findall(r'({.*?})', result)[0]


# string = '{"1":"82686","2":"73363","3":"52320","4":"49171","5":"46838","6":"\
# 43687","7":"36339","8":"36067","9":"35917","10":"35570","11":"32912","12":"34\
# 357","13":"33653","14":"31370","15":"33803","16":"32647","17":"30681","18":"32\
# 163","19":"29455","20":"31213","21":"30199","22":"28536","23":"30041","24":"\
# 28862","25":"29439","26":"29469","27":"29378","28":"29678","29":"31427","\
# 30":"53411"}'

tmp_dict = json.loads(string)
for k, v in tmp_dict.items():
    print(k, v)
# 1 82686
# 2 73363
# 3 52320
# 4 49171
# 5 46838
# 6 43687
# 7 36339
2017年6月22日 16:45