【发布时间】:2020-07-05 02:51:34
【问题描述】:
这是我用来在没有 API.no client_id 或访问令牌的情况下获取主题标签顶部图像的代码。它在我的本地主机中运行良好。但是当我把它放在在线主机(pythoneverywhere)上时。它没有!
def hashtagTracker(request):
if request.GET.get('num1'):
hashtag = request.GET['num1']
# print("\033[1m" + "Scraping/analyzing posts for " + hashtag + "..." + "\033[0m")
page = requests.get("https://www.instagram.com/explore/tags/" + hashtag[1:])
posts = json.loads(page.text[page.text.find("window._sharedData") + 21: page.text.find("};</script>") + 1])
postCount = posts["entry_data"]["TagPage"][0]["graphql"]["hashtag"]["edge_hashtag_to_media"]["count"]
似乎在在线版本中,请求被定向到登录门户。而这在 localhost 版本中没有发生。谁能帮我解决这个问题并让它在在线主机上运行并节省我的一周?
谢谢你,对不起我的英语:)
【问题讨论】:
-
将html保存为文件并分析。我推荐使用
BeautifulSoup来解析html