C# - 只能将赋值,调用,递增,递减和新对象表达式用作语句

时间:2017-08-16 02:04:56

标签: c#

我在尝试运行此语句时收到上述错误:

import requests
import re
from bs4 import BeautifulSoup

def getLinks(url):
    response = requests.get(url)
    if response.status_code != 200: return []

    html_page = response.content
    soup = BeautifulSoup(html_page, "html.parser")
    links = []

    for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
        links.append(link.get('href'))

    # remove duplicates
    links = list(set(links))

    return links

def count_dead_links(url, recursion_depth=0):

    count = 0

    for link in getLinks(url):
        response = requests.get(link)
        if response.status_code == 404:
            count += 1
        else:
            if recursion_depth > 0:
                count += count_dead_links(link, recursion_depth-1)

    return count

# returns count of dead links on the page
print(count_dead_links("http://madisonmemorial.org/"))

# returns count of dead links on the page plus all the dead links 
# on all the pages that result after following links that work.
print(count_dead_links("http://madisonmemorial.org/", 1))

2 个答案:

答案 0 :(得分:2)

您正在编写布尔语句,而不是声明语句

// This results in True or False.
command == "debug";

// This assigns the value of command to 'debug'
command = "debug";

答案 1 :(得分:1)

取决于您要实现的目标,应该是以下任何一种:

internal static void getCommand(string command, string arg)
{
    // comparison
    if (command == "debug")
    {
      // do something
    } 
}

OR

internal static void getCommand(string command, string arg)
{
    //assignment
    command = "debug";
}

您的代码目前都没有。不确定你的代码需要做什么,但其中一个应该是它..