gpt4 book ai didi

Python 请求数组中的 html 打印响应

转载 作者:太空狗 更新时间:2023-10-30 01:36:22 25 4
gpt4 key购买 nike

我正在尝试检查链接是否包含 http 并打印 URL。

import requests
from requests_html import HTMLSession
import sys

link = "http://www.tvil.me/view/93/4/8/v/%D7%90%D7%99%D7%99_%D7%96%D7%95%D7%9E%D7%91%D7%99_IZombie.html"
enter_episodes = HTMLSession().get(link)
page = enter_episodes.html
s = page.xpath("//*[@class='view-watch-button']/a")
for l in s:
link = l.links
if link != "set()":
print(link)

响应:

{'http://streamcloud.eu/ga4m4hizbrfb/iZombie.S04E08.HDTV.x264-SVA.mkv.html'}
{'http://uptostream.com/77p26f7twwhe'}
set()
{'https://clipwatching.com/aog2ni06rzjt/rrFhepnbFfpt6xg.mkv.html'}
set()
[Finished in 1.7s]

我试图删除 set() 响应并只获取没有 {''} 的链接。

最佳答案

你只需要确保集合的长度大于一,然后弹出它:

import requests
from requests_html import HTMLSession
import sys

link = "http://www.tvil.me/view/93/4/8/v/%D7%90%D7%99%D7%99_%D7%96%D7%95%D7%9E%D7%91%D7%99_IZombie.html"
enter_episodes = HTMLSession().get(link)
page = enter_episodes.html
s = page.xpath("//*[@class='view-watch-button']/a")
for l in s:
link = l.links
if len(link) > 0: # make sure it has a value
print(link.pop()) # get the last value (in your case, the only one)

关于Python 请求数组中的 html 打印响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com