LoginSignup
0
0

More than 3 years have passed since last update.

instagramからLocationをscrapeする方法

Posted at

Instagramから位置情報をscrape

insta.py
$pip3 install insta-scrape

from instascrape import Location
place_url = 'https://www.instagram.com/explore/locations/470867993/'
place = Location(place_url)
place.scrape()
latitude = place.latitude
longitude = place.longitude
command
$python manage.py shell
In [1]: from instascrape import Location

In [2]: place_url = 'https://www.instagram.com/explore/locations/470867993/'

In [3]: place = Location(place_url)

In [4]: place.scrape()
/Users/takamariku/pythonProject/venv/lib/python3.9/site-packages/instascrape/core/_static_scraper.py:134: MissingCookiesWarning: Request header does not contain cookies! It's recommended you pass at least a valid sessionid otherwise Instagram will likely redirect you to their login page.
  warnings.warn(
In [5]: latitude = place.latitude

In [6]: latitude
Out[6]: 35.550838

In [7]: longitude = place.longitude

In [8]: longitude
Out[8]: 139.788537
In [14]: place.to_dict()
Out[14]: 
{'id': '470867993',
 'name': '羽田空港 国内線第2ターミナル',
 'has_public_page': True,
 'latitude': 35.550838,
 'longitude': 139.788537,
 'slug': '2',
 'blurb': '',
 'website': 'https://www.tokyo-airport-bldg.co.jp/',
 'phone': '03-5757-8111',
 'primary_alias_on_fb': '',
 'stress_address': nan,
 'zip_code': nan,
 'city_name': 'Hanedakuukou',
 'region_name': nan,
 'country_code': 'JP',
 'amount_of_posts': 3492}

place.to_dict()のcomandを入力すると、その位置情報の全ての情報が表示される。

終わり

instascrapeでは自分が投稿している情報、位置情報など様々な情報をscrapeできる。Locationの他にも、自分のprofile情報を取得できる、from instascrape import Profileなどのmoduleもある。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0