我正在尝试使用 chrome webdriver 用 selenium 抓取 Instagram。我需要获取 XHR 响应信息,我尝试了“browsermob-proxy”,但该信息还不够:
server = Server("/home/doruk/Downloads/browsermob-proxy 2.1.4/bin/browsermob-proxy")
server.start()
time.sleep(1)
proxy = server.create_proxy()
time.sleep(1)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
browser = webdriver.Chrome(chrome_options=chrome_options)
##############################################
####This is output of proxy.har in json format.
{
"comment": "",
"serverIPAddress": "155.245.9.55",
"pageref": "",
"startedDateTime": "2018-05-21T16:44:41.053+03:00",
"cache": {},
"request": {
"comment": "",
"cookies": [],
"url": "https://scontent-sof1-1.cdninstagram.com/vp/e95312434013bc43a5c00c458b53022cb/5BC46751/t51.2885-19/s150x150/26432586_139925760144086_726193654523232256_n.jpg",
"queryString": [],
"headers": [],
"headersSize": 528,
"bodySize": 0,
"method": "GET",
"httpVersion": "HTTP/1.1"
},
当我在内容中单击“加载更多评论”时,会出现类似这样的链接
https://www.instagram.com/graphql/query/?query_hash=33ba35000cb50da46f5b5e889df7d159&variables=%7B "shortcode"%3A"Bi9ZURdA6Gn"%2C"first"%3A36%2C"after"%3A"AQBr-wP7U4Ykr1QRH7PYJ1a0KQivhS0Ndwae-5F8vrZ5sf1eA_Bfgn4dZ0ql0pwUf9GXPm_LPyhtCnlhH6YOHfuNstwXK9VZuUIR4zD3k24s6Q" %7D
出现了,我需要它里面的信息。有没有办法处理这种情况?
我只需要“?query_hash =”的东西。