【发布时间】:2016-08-10 10:48:07
【问题描述】:
您好,我的代码有问题,我尝试使用此代码搜索一个特定的 url,但它没有显示任何内容
from BeautifulSoup import BeautifulSoup
import urllib2
import re
html_page = urllib2.urlopen(url)
soup = BeautifulSoup(html_page)
for link in soup.findAll('a', attrs={'href': re.compile("^http://www.fiuxy.net/misc.php")}):
print link.get('href')
我只想要它有“10”文本的链接,它每次都会改变,(每次都不一样)
我做错了什么?
对不起,如果我的英语不好,因为我是西班牙语:(
【问题讨论】:
-
soup.select('.dar-puntos > a')[-1].text -
我在哪里添加的? @AvinashRaj
-
用上面的替换for循环,不要忘记在此之前添加打印。
-
for link in soup.select('.dar-puntos > a')[-1].text: print link喜欢这样吗? -
不,
print soup.select('.dar-puntos > a')[-1].text
标签: python url beautifulsoup