【发布时间】:2020-09-07 04:45:29
【问题描述】:
在这段代码中,我认为我犯了一个错误,因为当我打印它时我没有得到正确的json,实际上我什么也没得到,但是当我索引脚本时我得到了json,但使用@987654324 @ 什么都没有出现,我只想要 json。
代码:
from bs4 import BeautifulSoup
from urllib.parse import quote_plus
import requests
import selenium.webdriver as webdriver
base_url = 'https://www.instagram.com/{}'
search = input('Enter the instagram account: ')
final_url = base_url.format(quote_plus(search))
response = requests.get(final_url)
print(response.status_code)
if response.ok:
html = response.text
bs_html = BeautifulSoup(html)
scripts = bs_html.select('script[type="application/ld+json"]')
print(scripts[0].text)
【问题讨论】:
-
您使用了什么搜索字符串?我在repl code 中稍微调整了您的代码,但在输入
"abcd"时它可以工作。 -
它没有提供脚本对吗?
-
如果
search = "abcd",它是一个公共页面。如果search="damodar.dahal"是我的私人 Instagram 帐户,则它不起作用。 -
我明白了,它在 python 中对我有用。你能查一下我的代码是否有错误,而不是修改后的错误
标签: python json web-scraping beautifulsoup