首页 > 解决方案 > Python网页抓取图片路径,但标签和值不在同一行,无法得到结果

问题描述

我正在尝试抓取图片,但最后我发现标签和值不在同一行,所以当我使用 xpath 获取值但失败时。这是我的代码:

import requests,random,re,os
from fake_useragent import UserAgent
from lxml import etree
url='https://www.webtoon.xyz/read/what-does-the-fox-say/chapter-133/'
header ={'user_agent':random.choice(UserAgent().chrome)}
req=requests.get(url).content.decode('utf-8')
html=etree.HTML(req)
img_list=html.xpath("//div[@class='reading-content']/div[@class='page-break no-gaps']//@src")
print(img_list)

它返回空>>[] 实验室和价值

是不是标签src和值不在同一行所以导致空结果?我怎样才能得到路径?

标签: pythonweb-scraping

解决方案


推荐阅读