0
我想从URL下载位置细节从Instagram刮,但我不能使用加载更多的选项来从网址刮更多的位置。如何使用加载更多选项与非头部网页刮板[Instagram]
我很欣赏关于如何修改代码的建议,或者需要使用哪个新代码块来获取特定网址中的所有可用位置。
代码:
import re
import requests
import json
import pandas as pd
import numpy as np
import csv
from geopy.geocoders import Nominatim
def Location_city(F_name):
path="D:\\Everyday_around_world\\instagram\\"
filename=path+F_name
url1="https://www.instagram.com/explore/locations/c1027234/hyderabad-india/"
r = requests.get(url1)
df3=pd.DataFrame()
match = re.search('window._sharedData = (.*);</script>', r.text)
a= json.loads(match.group(1))
b=a['entry_data']['LocationsDirectoryPage'][0]['location_list']
for j in range(0,len(b)):
z= b[j]
if all(ord(char) < 128 for char in z['name'])==True:
x=str(z['name'])
print (x)
geolocator = Nominatim()
location = geolocator.geocode(x,timeout=10000)
if location!=None:
#print((location.latitude, location.longitude))
df3 = df3.append(pd.DataFrame({'name': z['name'], 'id':z['id'],'latitude':location.latitude,
'longitude':location.longitude},index=[0]), ignore_index=True)
df3.to_csv(filename,header=True,index=False)
Location_city("Hyderabad_locations.csv")
在此先感谢您的帮助..
谢谢你这么多。解决方案就像一个魅力..我只能在未来24小时内分配奖励点..将尽快..再次谢谢.. –