首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用网站爬行链接循环只打印5个链接

使用网站爬行链接循环只打印5个链接
EN

Stack Overflow用户
提问于 2016-09-22 12:54:38
回答 1查看 24关注 0票数 0

只需从url中提到的特定网站打印10个品牌名称,请帮助我。

代码语言:javascript
复制
from re import findall
import csv
import re
import urllib
from bs4 import BeautifulSoup

def brand_name_link("https://priceraja.com/mobile/brands/"):    
    htmlfile= urllib.urlopen(url)
    #htmltext = htmlfile.read()
    data=[]
    link=[]
    soup = BeautifulSoup(htmlfile, 'html.parser')
    name_box = soup.find('ul', attrs={'class': 'top-brands'})   

    for tag in name_box.find_all('img'):
        tag.replaceWith('')
        link=tag
    link=name_box.find_all('a')

    print link
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-22 13:25:44

代码语言:javascript
复制
def brand_name_link(url):   
    htmlfile= urllib.urlopen(url)
    #htmltext = htmlfile.read()
    data=[]
    link=[]
    soup = BeautifulSoup(htmlfile, 'html.parser')
    name_box = soup.find('ul', attrs={'class': 'top-brands'})   

    for tag in name_box.find_all('img'):
        tag.replaceWith('')
        link=tag
    link=name_box.find_all('a')
    k=0
    while k<len(link):
        print link[k]
        k+=1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39639681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档