我想从嵌入式谷歌地图下载标记,以便找到标记所在的国家/地区。我没有创建地图,因此我无法导出KML。我尝试使用请求下载内容并使用Beautiful Soup解析HTML内容,然后通过解析slimit中的JavaScript来查找国家/地区信息。然而,这只允许我在地图上找到少量航路点。该组织在100多个国家/地区开展业务,但我的搜索仅返回14个国家/地区名称。我想知道我是否需要使用谷歌地图特定模块?
示例代码:
import requests
from bs4 import BeautifulSoup
from slimit import ast
from slimit.parser import Parser
from slimit.visitors import nodevisitor
#Get HTML Content
with requests.Session() as c:
page = c.get("http://www.ifla-world-report.org/cgi-bin/static.ifla_wr.cgi?dynamic=1&d=ifla_wr_browse&page=query&interface=map")
pContent = page.content
#Parse through HTML and Grab the Javascript
soup = BeautifulSoup(pContent)
text_to_find = "country"
for script in soup.find_all('script'):
#Now Parse through the Javascript to find the country variable
lookat = Parser()
tree = lookat.parse(script.text)
for node in nodevisitor.visit(tree):
if isinstance(node, ast.Assign):
value = getattr(node.left, 'value', '')
if text_to_find in value:
country = getattr(node.right, 'value', '')
print country[1:-1]