使用以下代码:
prop_img = prop_lst.find_all('a',{'class':'mpi_img_link'})
我得到以下输出的列表:
[<a class="mpi_img_link" href="/homedetail/5324-palm-royale-blvd-sugar-land-tx-77479/2504873" style="background-image:url(https://photos.harstatic.com/205383563/lr/img-1.jpeg?ts=2022-03-02T17:03:25.300);"></a>,
<a class="mpi_img_link" href="/homedetail/27-riverstone-island-dr-sugar-land-tx-77479/13157541" style="background-image:url(https://photos.harstatic.com/184277385/lr/img-1.jpeg?ts=2020-04-07T14:50:50.960);"></a>,
<a class="mpi_img_link" href="/homedetail/23-beacon-hl-sugar-land-tx-77479/2507526" style="background-image:url(https://photos.harstatic.com/205977706/lr/img-1.jpeg?ts=2022-03-20T23:10:23.777);"></a>,
<a class="mpi_img_link" href="/homedetail/0-hagerson-rd-sugar-land-tx-77479/2375356" style="background-image:url(https://photos.harstatic.com/205015725/lr/img-1.jpeg?ts=2022-02-16T10:20:54.847);"></a>,
<a class="mpi_img_link" href="/homedetail/5-cypress-valley-ct-sugar-land-tx-77479/2505565" style="background-image:url(https://photos.harstatic.com/208809599/lr/img-1.jpeg?ts=2022-06-27T14:34:55.917);"></a>,
<a class="mpi_img_link" href="/homedetail/21-grand-mnr-sugar-land-tx-77479/2506201" style="background-image:url(https://photos.harstatic.com/201552628/lr/img-1.jpeg?ts=2021-10-21T10:55:15.270);"></a>,
<a class="mpi_img_link" href="/homedetail/427-w-alkire-lake-dr-sugar-land-tx-77478/10240223" style="background-image:url(https://photos.harstatic.com/203290759/lr/img-1.jpeg?ts=2022-01-02T15:48:57.463);"></a>,
<a class="mpi_img_link" href="/homedetail/1309-n-horseshoe-dr-sugar-land-tx-77478/2390056" style="background-image:url(https://photos.harstatic.com/209561396/lr/img-1.jpeg?ts=2022-06-27T21:04:42.547);"></a>,
<a class="mpi_img_link" href="/homedetail/1217-n-horseshoe-dr-sugar-land-tx-77478/10101841" style="background-image:url(https://photos.harstatic.com/207957668/lr/img-1.jpeg?ts=2022-06-12T19:32:34.500);"></a>,
<a class="mpi_img_link" href="/homedetail/1990-hagerson-rd-sugar-land-tx-77479/15860752" style="background-image:url(https://photos.harstatic.com/208557478/lr/img-1.jpeg?ts=2022-06-02T16:14:04.770);"></a>,
<a class="mpi_img_link" href="/homedetail/15202-old-richmond-rd-sugar-land-tx-77498/2387668" style="background-image:url(https://photos.harstatic.com/194038254/lr/img-1.jpeg?ts=2021-03-03T18:51:20.263);"></a>,
<a class="mpi_img_link" href="/homedetail/323-w-alkire-lake-dr-sugar-land-tx-77478/2390859" style="background-image:url(https://photos.harstatic.com/206236194/lr/img-1.jpeg?ts=2022-03-29T10:03:14.540);"></a>]
这太棒了!现在我寻求得到'style="background-image:url"' url,这是下面的输出。I doNOT想要href链接
https://photos.harstatic.com/205383563/lr/img-1.jpeg?ts=2022-03-02T17:03:25.300
https://photos.harstatic.com/184277385/lr/img-1.jpeg?ts=2020-04-07T14:50:50.960
:
:
:
https://photos.harstatic.com/206236194/lr/img-1.jpeg?ts=2022-03-29T10:03:14.540
我认为你应该使用下面的CSS选择器,但我仍然无法实现最终目标。有人能帮帮忙吗?谢谢你!
for img in prop_img:
print(prop_lst.select('style'))
差不多了。试一试:
for img in prop_img:
print(img['style'])
取出url部分:
import re
for img in prop_img:
url = re.search('((.*))', img['style']).group(1)
print(url)