我希望在一个包含各种交通摄像头位置的交互式地图上刮取图像的源URL,并将它们作为列表导出到JSON或CSV。因为我试图从不同的网站收集这些数据,所以我尝试使用parsehub和octoparse,但没有效果。我以前尝试使用BS4和selenium,但是无法使用src提取div / img标记。任何帮助都将不胜感激。下面是两个不同网站的例子,它们有着相似但不同的方法来保存图像。

https://cwwp2.dot.ca.gov/vm/iframemap.htm (cal trans )

发布于 2022-07-29 19:37:53
图像名称(用于trip检查)来自api调用。您需要请求闭路电视ids,然后才能构建urls。
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'X-Requested-With': 'XMLHttpRequest',
'DNT': '1',
'Connection': 'keep-alive',
'Referer': 'https://tripcheck.com/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
}
params = {
'dt': '1659122796377',
}
response = requests.get('https://tripcheck.com/Scripts/map/data/cctvinventory.js', params=params, headers=headers)
response.json()['features'][0]['attributes']['filename']产出:
'AstoriaUS101MeglerBrNB_pid392.jpg'上面,迭代json响应中的属性数组。然后是网址:
import time
cam = response.json()['features'][0]['attributes']['filename']
rand = str(time.time()).replace('.','')[:13]
f'https://tripcheck.com/RoadCams/cams/{cam}?rand={rand}'产出:
'https://tripcheck.com/RoadCams/cams/AstoriaUS101MeglerBrNB_pid392.jpg?rand=1659123325440'注意,rand参数似乎是时间戳的一部分。与原始请求中的'dt‘参数一样。您可以使用time.time()生成时间戳,并根据需要对其进行操作。
https://stackoverflow.com/questions/73169355
复制相似问题