【问题标题】:Error with code Python Beautifulsoup extract specific link with text代码错误 Python Beautifulsoup 提取带有文本的特定链接
【发布时间】: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


【解决方案1】:

谢谢大家,但我自己用硒解决了,

from selenium import webdriver
driver.get(url)
puntos = driver.find_element_by_link_text(u"10")
print (puntos.get_attribute('href'))

【讨论】:

    猜你喜欢
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2021-11-20
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多