这个是文档
from lxml import etree
from pyquery import PyQuery as pq
import time
import json
import requests
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
}
url="https://m.weibo.cn/api/container/getIndex?containerid=100103type%3D1%26q%3D%E7%96%AB%E6%83%85&page_type=searchall&page=2"
page_text=requests.get(url=url,headers=headers).text
cards=json.loads(page_text)["data"]["cards"]
for card in cards:
a=pq(card["mblog"]["text"]).text()
b=card["mblog"]["source"]
c=card["mblog"]["user"]["screen_name"]
d=card["mblog"]["created_at"]
e=card["scheme"]
print(a)
print(b)
print(c)
print(d)
print(e)
print('##############################################################')
这个是json()
from lxml import etree
from pyquery import PyQuery as pq
import time
import json
import requests
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
}
url="https://m.weibo.cn/api/container/getIndex?containerid=100103type%3D1%26q%3D%E7%96%AB%E6%83%85&page_type=searchall&page=2"
page_text=requests.get(url=url,headers=headers).json()
cards=page_text["data"]["cards"]
for card in cards:
a=pq(card["mblog"]["text"]).text()
b=card["mblog"]["source"]
c=card["mblog"]["user"]["screen_name"]
d=card["mblog"]["created_at"]
e=card["scheme"]
print(a)
print(b)
print(c)
print(d)
print(e)
print('##############################################################')