小编Ibr*_*ter的帖子

关于Rap Genius w/Python的Web Scraping Rap歌词

我有点像编码新手,我一直试图通过使用Beautiful Soup(用于从HTML中提取数据的Python库)从Rap天才http://genius.com/artists/Andre-3000中删除Andre 3000的歌词.和XML文件).我的最终目标是以字符串格式提供数据.这是我到目前为止:

from bs4 import BeautifulSoup
from urllib2 import urlopen

artist_url = "http://rapgenius.com/artists/Andre-3000"

def get_song_links(url):
    html = urlopen(url).read()
    # print html 
    soup = BeautifulSoup(html, "lxml")
    container = soup.find("div", "container")
    song_links = [BASE_URL + dd.a["href"] for dd in container.findAll("dd")]

    print song_links

get_song_links(artist_url)
for link in soup.find_all('a'):
    print(link.get('href'))
Run Code Online (Sandbox Code Playgroud)

所以我需要其他代码的帮助.如何将他的歌词变成字符串格式?然后我如何使用自然语言工具包(NLTK)来标记句子和单词.

python beautifulsoup nltk html-parsing web-scraping

8
推荐指数
1
解决办法
6384
查看次数

在Java中计算正整数的第n个根

我的任务是编写一个程序,提示用户输入一个正a整数和一个n大于2 的整数 ,并将正整数的第n个根的值打印a到屏幕上,精确到100个位置.我曾经Math.pow能够获得根,我觉得我已经做好了一切.唯一的问题是,每次我运行我的程序时,输出的是1.0,无论什么数字I输入an.我的代码有什么问题?

import java.util.Scanner;
import java.lang.Math;

public class Q8 {

    public static void main(String[] args) {

    System.out.println("Enter a positive number: ");
    Scanner in = new Scanner(System.in);
    double a = in.nextDouble();

    System.out.println("Enter an integer greater than 2: ");
    Scanner in2 = new Scanner(System.in);
    int n = in.nextInt();

    System.out.println(pow (a,n));
    }

private static double pow(double a, int n) {
      if (n == 0){
            return 1;
      }

      else{ …
Run Code Online (Sandbox Code Playgroud)

java recursion square-root

4
推荐指数
2
解决办法
2285
查看次数