簡體   English   中英

web 在 python 中抓取:嘗試從使用 ZC2ED0329D2D3CF57CCDZ58 的 img 中給出的 url 獲取坐標

[英]web scraping in python: trying to get coordinates from a url given in a img using BeautifulSoup

我正在嘗試獲取 URL 中的坐標,該坐標在同一行中分開的兩個鏈接中給出。 實際上,我開始爬取所有 URL 然后是坐標,但是,直接獲取坐標可能更容易。 我正在使用 beautifulSoup 並且我有下一個 HTML 代碼。

在此處輸入圖像描述

As you see, the url is given in the 'div class' followed by an 'id', then an img srcset and finally an src, if you realize, the <img src=> and the have the URL where inside of each URL包含坐標 (19.3410346%2C-99.1579533)。 我不知道,我也不明白我怎么能得到它。

我正在使用 bs4 和 python 3.9

from bs4 import BeautifulSoup 
import requests 

url='https://departamento.metroscubicos.com/MLM-912728287-departamento-en-zona-privilegiada-en-coyoacan-_JM#position=1&search_layout=grid&type=item&tracking_id=0264c9e9-5bf3-4964-bc39-b7b3609c4a7a' 
resp=requests.get(url) 
soup=BeautifulSoup(resp.content, "html.parser") 

它們存在於腳本標簽中。 我只是將它們從響應文本中正則表達式

import requests, re

r = requests.get('https://departamento.metroscubicos.com/MLM-912728287-departamento-en-zona-privilegiada-en-coyoacan-_JM#position=1&search_layout=grid&type=item&tracking_id=0264c9e9-5bf3-4964-bc39-b7b3609c4a7a')

print('latitude = ', re.search(r'latitude: (.*?),',r.text).group(1))
print('longitude = ', re.search(r'longitude: (.*?),', r.text).group(1))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM