我想从以下网址:(https://www.strongmotioncenter.org/cgi-bin/CESMD/Multiplesearch1_DM2.pl?event_name=&magmin=&magmax=&byear=&eyear=&country=Any&state=Any&stn_ident=&type=BLD&Material=Concrete&Height=&siteclass=Any&accmin=&accmax=&hdistmin=&hdistmax=)我找不到通过webdriver的,硒正确的图像(.JPG),并beautifulsoup
你可以看到下站列中的链接下载数百张照片,我想自动点击它并在新浏览器中找到jpg(左侧)文件,然后下载它。
我用jupyter笔记本写我的Python代码,如下图所示:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
import urllib.request
import requests
chrome=webdriver.Chrome('/Users/user/Downloads/software
/chromedriver_win32/chromedriver')
chrome.get("https://www.strongmotioncenter.org/cgi-
bin/CESMD/Multiplesearch1_DM2.pl?
event_name=&magmin=&magmax=&byear=&eyear
=&country=Any&state=Any&stn_ident=&type=BLD&Material
=Concrete&Height=&siteclass=Any&accmin=&accmax=&hdistmin=&hdistmax=")
stations = chrome.find_element_by_css_selector('.xlink')
stations.click()
url_link = chrome.current_url
soup = BeautifulSoup(urllib.request.urlopen(url_link),"lxml")
figure = soup.find_all('.jpg')
print(figure)
它总是打印出什么。但是,如果我写的:
figure = soup.find_all('img')
它将返回:
[<img onclick="url("'+" processed=""
src="../../NCESMD/images/save_32.gif"/>, <img onclick="url("'+" raw=""
src="../../NCESMD/images/save_32.gif"/>]
这是不是我想要的图像文件。
我真的不知道发生了什么事。
谢谢你的时间。我真的很感激。
有一个在使用浏览器F12工具的网站。查看网络活动和JavaScript的用法。 –