- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从网站检索第一个下载链接,但我的代码返回的内容不止于此,我不确定原因。
这是我的一段代码:
site_search = "http://mp3skull.com/mp3/tubidy.html"
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0'
class MyOpener(FancyURLopener, object):
version = user_agent
myopener = MyOpener()
page = myopener.open(site_search)
html = etree.HTML(page.read())
xpath = "//a[@style = 'color:green;'][1]/@href"
filtered_html = html.xpath(xpath)
print(filtered_html)
我的代码返回:
['http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3', 'http://dc357.4shared.com/img/1396413489/41200d37/dlink__2Fdownload_2FOfQCGDtd_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1394581159/99fd9e7/dlink__2Fdownload_2FoENbSCE2_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1394580769/9e8391f3/dlink__2Fdownload_2Fu4IeKpFK_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1386745964/e7f6dcb/dlink__2Fdownload_2F303C_5FUCB_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1386568212/616a9b6e/dlink__2Fdownload_2Fcw_5FeT72M_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc540.4shared.com/img/1386000196/b6a127da/dlink__2Fdownload_2FEyTD5P9j_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc337.4shared.com/img/1330719927/4f96e0d1/dlink__2Fdownload_2FiYGiVen4_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc242.4shared.com/img/1328992471/f164c1bb/dlink__2Fdownload_2Fsgz8qSBW_3Ftsid_3D00000000-000000-000000/preview.mp3', 'http://dc539.4shared.com/img/1317978255/68f8329d/dlink__2Fdownload_2FSi_5Fka2Pm_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc402.4shared.com/img/1236310800/70345122/dlink__2Fdownload_2FYWU0Aksu_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc150.4shared.com/img/1236293916/681798eb/dlink__2Fdownload_2Fhe_5FMHVoM_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc263.4shared.com/img/1233805806/ab16f2f1/dlink__2Fdownload_2FFp1E7eV8_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc392.4shared.com/img/1194298272/dda6a2b0/dlink__2Fdownload_2Fq1Y3PdRO_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc392.4shared.com/img/1186905892/803a5130/dlink__2Fdownload_2FubH7xctu_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc429.4shared.com/img/1183115738/125793e3/dlink__2Fdownload_2F9Y3zzp-K_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc459.4shared.com/img/1181881278/421221cb/dlink__2Fdownload_2FjstpNTCi_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc453.4shared.com/img/1181881110/18d5b026/dlink__2Fdownload_2F8mmM2BcS_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc120.4shared.com/img/1181875882/25fa514a/dlink__2Fdownload_2F0_5F0UxQuu_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc471.4shared.com/img/1181868760/9121abb8/dlink__2Fdownload_2Fq2ykXJ7Q_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc381.4shared.com/img/1177326344/661ba359/dlink__2Fdownload_2FHztHPN1O_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc201.4shared.com/img/1146076462/de8d83e2/dlink__2Fdownload_2Fqaumhl-G_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc352.4shared.com/img/1142200306/a439f02c/dlink__2Fdownload_2FECiq0Wc8_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc392.4shared.com/img/1137314077/bf9aa3d8/dlink__2Fdownload_2F1ZQOMJ9O_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc362.4shared.com/img/1128611400/34471996/dlink__2Fdownload_2FEF12Czzg_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc196.4shared.com/img/1124868095/a0646612/dlink__2Fdownload_2FruOhPkHz_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc508.4shared.com/img/1124145685/1257f194/dlink__2Fdownload_2FPUqL0qz8_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1120296900/3946f5cc/dlink__2Fdownload_2FqsLK3WC9_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1091112724/d363d3c4/dlink__2Fdownload_2FylEZuq80_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc394.4shared.com/img/1086814685/542051eb/dlink__2Fdownload_2FiRSSrUEu_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc340.4shared.com/img/1086805965/4423758d/dlink__2Fdownload_2FAXmv12yD_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc397.4shared.com/img/1086804062/6d2abcc4/dlink__2Fdownload_2FIWWI8tmV_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc339.4shared.com/img/1086802960/a99eb9bb/dlink__2Fdownload_2FlxGG5VBU_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc402.4shared.com/img/1086799043/2637e6a9/dlink__2Fdownload_2FSjcCMKQ5_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc352.4shared.com/img/1086798986/4d8501c0/dlink__2Fdownload_2Fk1ZHbbCa_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc364.4shared.com/img/1086798016/93968106/dlink__2Fdownload_2FgNBZbBqG_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc253.4shared.com/img/1086794519/4f34e1c4/dlink__2Fdownload_2FBZWIHqC4_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1086790487/f7ee8aea/dlink__2Fdownload_2FbvASkRUI_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/1084754225/3a8f1481/dlink__2Fdownload_2FY2rkufif_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc495.4shared.com/img/1039479528/73f2fa3c/dlink__2Fdownload_2FKWsm3WJ-_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc145.4shared.com/img/975452680/1597c3a2/dlink__2Fdownload_2FQ2VX9l6W_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc252.4shared.com/img/933590669/b1f79b67/dlink__2Fdownload_2F0hbdsF2M_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc120.4shared.com/img/885049589/d1a62f17/dlink__2Fdownload_2FmC_5F1JDXl_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc224.4shared.com/img/884702525/bb0c917b/dlink__2Fdownload_2F46GnfVxK_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc337.4shared.com/img/849169766/fd8d3498/dlink__2Fdownload_2F-hynMHjn_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc431.4shared.com/img/844202587/a88f9c21/dlink__2Fdownload_2F85HCohcN_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc184.4shared.com/img/838092829/30bd6ae8/dlink__2Fdownload_2Ffil3BIUA_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc430.4shared.com/img/838091664/324b51b5/dlink__2Fdownload_2FfrzQcwBu_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc441.4shared.com/img/838089810/882d2f3e/dlink__2Fdownload_2FqUMmG5Zl_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc190.4shared.com/img/838088957/cb5b72cb/dlink__2Fdownload_2FiR6VJUSC_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc433.4shared.com/img/838087554/32bca43/dlink__2Fdownload_2Ff3_5Fn7pKY_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc316.4shared.com/img/838086255/c9df8b35/dlink__2Fdownload_2FKMBk8wZI_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc445.4shared.com/img/838084096/55ee8966/dlink__2Fdownload_2FM9Qw6AwI_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc415.4shared.com/img/838082894/9098e62e/dlink__2Fdownload_2F8DGix4I5_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc233.4shared.com/img/838081788/99dc7397/dlink__2Fdownload_2Ft-4IKE5C_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc445.4shared.com/img/838081320/6ae1bbf3/dlink__2Fdownload_2FBy95Sp_5FU_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc387.4shared.com/img/838079502/f5b07bd1/dlink__2Fdownload_2FF_5FyXSg9E_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc429.4shared.com/img/842513873/dbab9cf3/dlink__2Fdownload_2FeNLkoppN_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc424.4shared.com/img/827830064/127ba0d9/dlink__2Fdownload_2Fj8emrNnO_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc270.4shared.com/img/822099181/7483e90e/dlink__2Fdownload_2F7xIdA4q6_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc308.4shared.com/img/822092067/d5a08c83/dlink__2Fdownload_2FM26G9oiJ_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc198.4shared.com/img/800516614/3d006c3d/dlink__2Fdownload_2Fdz18B2dB_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc388.4shared.com/img/793902768/4eeb6c1d/dlink__2Fdownload_2FnRMBB2bB_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc362.4shared.com/img/788822785/d1e8e98f/dlink__2Fdownload_2Fqs2Ky8y6_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc183.4shared.com/img/788819652/6b419587/dlink__2Fdownload_2FlnWIeFyL_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc391.4shared.com/img/788813387/c7f33dca/dlink__2Fdownload_2FvmPZSPCp_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc198.4shared.com/img/788809769/eb1c5c4b/dlink__2Fdownload_2F0r6tlUex_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc280.4shared.com/img/788804149/2fcd9aa6/dlink__2Fdownload_2FBZSQjBQM_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc280.4shared.com/img/788803303/35275a6b/dlink__2Fdownload_2FsH4BjUMw_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc198.4shared.com/img/781278584/363504d6/dlink__2Fdownload_2Fof2zYynb_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc405.4shared.com/img/717415145/3d6233e1/dlink__2Fdownload_2FkxXODf-m_3Ftsid_3D20130107-14410-24515ba/preview.mp3', 'http://dc376.4shared.com/img/717284773/98545fac/dlink__2Fdownload_2FrreBjY6x_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc397.4shared.com/img/716180972/4a4cac7d/dlink__2Fdownload_2FPLBlw3hR_3Ftsid_3D20130107-14410-24515ba0/preview.mp3', 'http://dc302.4shared.com/img/7074
我知道从结果中获取第一个链接并不难,但我很好奇为什么我首先会得到这么多链接。
谢谢
最佳答案
//something[1] 返回其各自父级的第一个 thing 的所有值。 (//something)[1] 将返回文档中第一个东西。
所以你必须使用:
(//a[@style = 'color:green;'])[1]/@href
关于python - Xpath 返回的内容超出了预期(python、urllib、lxml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14202162/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!