【发布时间】:2017-08-19 13:27:27
【问题描述】:
我正在尝试从 watchseriesfree.to 网站上的特定文件主机中提取一些链接。在以下情况下,我需要 rapidvideo 链接,因此我使用正则表达式过滤掉那些带有包含 rapidvideo 的文本的标签
import re
import urllib2
from bs4 import BeautifulSoup
def gethtml(link):
req = urllib2.Request(link, headers={'User-Agent': "Magic Browser"})
con = urllib2.urlopen(req)
html = con.read()
return html
def findLatest():
url = "https://watchseriesfree.to/serie/Madam-Secretary"
head = "https://watchseriesfree.to"
soup = BeautifulSoup(gethtml(url), 'html.parser')
latep = soup.find("a", title=re.compile('Latest Episode'))
soup = BeautifulSoup(gethtml(head + latep['href']), 'html.parser')
firstVod = soup.findAll("tr",text=re.compile('rapidvideo'))
return firstVod
print(findLatest())
但是,上面的代码返回一个空白列表。我做错了什么?
【问题讨论】:
-
NB:
findAll在 bs4 中似乎已重命名为find_all。 (显然,bs3 版本一直保留,但无论如何我都会更新您的代码。)find_all函数签名也没有text参数,而是string参数。