【发布时间】:2019-10-27 16:55:01
【问题描述】:
我正在尝试从此结果页面上的“显示地图”按钮中抓取经纬度数据:https://www.psychologytoday.com/us/therapists/60148/374863?sid=5d01e84909804&ref=2&tr=ResultsName
这是我迄今为止尝试过的=
button = soup.find('button', {"data-event-label":'Address_MapButton'})
print(button['data-map-lat'])
完整代码: 导入请求 从 bs4 导入 BeautifulSoup 从 bs4.element 导入标签
zipcode = int(input("Zipcode: "))
url = 'https://www.psychologytoday.com/us/therapists/{0}'.format(zipcode)
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.text, 'html.parser')
result = soup.find(class_='results-column')
addressArray = []
for tag in result:
if isinstance(tag,Tag):
_class = tag.get("class")
if _class is None or _class is not None and "row" not in _class:
continue
link = (tag.find(class_='result-actions')).find('a',href=True)
_href = link['href']
address_link = requests.get(_href, headers=headers)
soup1 = BeautifulSoup(address_link.text, 'html.parser')
address = (soup1.find(class_='address')).find(class_="location-address-phone")
button = soup.find('button', {"data-event-label":'Address_MapButton'})
print(button['data-map-lat'])
print(addressArray)
我得到一个 None 回报。 我想查看纬度坐标。
【问题讨论】:
标签: python web-scraping beautifulsoup python-requests