猿问

网页抓取以从嵌入的谷歌地图链接中提取坐标

import requests

import urllib2

from bs4 import BeautifulSoup

from pprint import pprint

import pandas as pd

import bs4


url = 'https://www.namus.gov/MissingPersons/Case#/53061'

page = urllib2.urlopen(url)

soup = BeautifulSoup(page, 'html')

#print(soup.prettify())


findall = soup.find_all("a")


for link in findall:

    pprint(link.get("ng-href"))

当我运行代码时,我设置了一个元组而不是链接。我试过引用 href、src、ng-href 和 non work。当我真的需要将谷歌地图的链接作为字符串时,我只能拉取 subSection。


#I get this: u'{{subSection.mapLink()}}'

#when I really need this: #"http://www.google.com/maps/place/35.9467011,-84.03260329999999"

我尝试抓取的实际字符串如下所示:


<a ng-if="subSection.mapLink()" class="icon-text-link" ng-href="http://www.google.com/maps/place/35.9467011,-84.03260329999999" target="_blank" href="http://www.google.com/maps/place/35.9467011,-84.03260329999999">

                <i class="icon-location-pin"></i><span>Map</span>

            </a>


函数式编程
浏览 209回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答