0
私は現在、さまざまなレストランからウェブサイトから緯度と経度を引き出しようとしています。私は香港のこのレストランのHTMLを見ていました。私はここから緯度と経度をこすりしたいが、私は、私は、印刷しようとしたときにそれを得るように見えることはできませんPythonを使用してWebページからJavascriptテキストをスクラブする
HTML Code with the Latitude and Longitude
:私はこれを見つけたHTMLで
Restaurant I am attempting to scrape from
それ。以下は私のコードです。どんな提案も参考になります。
#import libraries
import requests
from bs4 import BeautifulSoup
import csv
#loop to move into the next pages. entries are in increments of 30 per page
for i in range(0, 1, 30):
#need this here for when you want more than 30
while i <= range:
i = str(i)
#url format offsets the restaurants in increments of 30 after the oa
url1 = 'https://www.tripadvisor.com/Restaurants-g294217-oa' + i + '-Hong_Kong.html#EATERY_LIST_CONTENTS'
r1 = requests.get(url1)
data1 = r1.text
soup1 = BeautifulSoup(data1, "html.parser")
for link in soup1.findAll('a', {'property_title'}):
#print 'https://www.tripadvisor.com/Restaurant_Review-g294217-' + link.get('href')
restaurant_url = 'https://www.tripadvisor.com/Restaurant_Review-g294217-' + link.get('href')
#print restaurant_url
r2 = requests.get(restaurant_url)
data2 = r2.text
soup2 = BeautifulSoup(data2, "html.parser")
for script in soup2.findAll('script', {'type', 'text/javascript', 'lat'}):
print script.string
セレンにはPython 3.4以上が必要ですか? – dtrinh
いいえ、Python 2.7で利用できます – amirouche