小编Mws*_*cer的帖子

美丽的汤选择Vs Find_all数据类型

我是webscraping的新手,似乎有两种方法来收集我正在寻找的所有html数据.

option_1 = soup.find_all('div', class_='p')

option_2 = soup.select('div.p')
Run Code Online (Sandbox Code Playgroud)

我看到option_1返回类'bs4.element.ResultSet'而option_2返回类'list'

我仍然可以使用for循环遍历option_1,那么有什么区别:

  1. select和find_all
  2. 'list'和bs4.element.ResultSet

python beautifulsoup

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

os.path.abspath vs os.path.dirname

这些在字符串值上是相等的,但它们真的相同吗?怎么回事?

import os

path_name1 = os.path.abspath(os.path.dirname(__file__))
path_name2 = os.path.dirname(os.path.abspath(__file__))

print(path_name1)
print(path_name2)
Run Code Online (Sandbox Code Playgroud)

python python-3.x os.path

6
推荐指数
1
解决办法
2106
查看次数

为什么“python -m pip install ...”需要“-m”?

我最近使用 piprequests在 python 2.7 中安装包,但是为了这样做,我必须使用:

python -m pip install requests 
Run Code Online (Sandbox Code Playgroud)

而不仅仅是:

python pip install requests
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误:

无法打开文件 'pip: [Errno 2] 没有这样的文件或目录

为什么我需要添加-m

pip python-2.7

4
推荐指数
1
解决办法
4438
查看次数

C# ICommand Can Execute

I was trying to understand the ICommand interface. I built an application with a button that uses a class called RelayCommand which inherits from ICommand. The class looks like this:

    class RelayCommand : ICommand
{
    private Action<object> _action;
    public RelayCommand(Action<object> action)
    {
        _action = action;
    }

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public void Execute(object parameter)
    {
        if(parameter != null)
        {
            _action(parameter);
        }
        else
        {
            _action("Hello World");
        }
    }

    //We need to include CanExecuteChange when using the Interface …
Run Code Online (Sandbox Code Playgroud)

c# wpf interface icommand

4
推荐指数
1
解决办法
1618
查看次数

在类中抓取一个类

我想class_="href"class_="_e4d". 基本上是想使用 BeautifulSoup 在一个类中抓取一个类。

from bs4 import BeautifulSoup
import selenium.webdriver as webdriver

url = ("https://www.google.com/search?...")

def get_related_search(url):
    driver = webdriver.Chrome("C:\\Users\\John\\bin\\chromedriver.exe")
    driver.get(url)
    soup = BeautifulSoup(driver.page_source)
    relate_result = soup.find_all("p", class_="_e4b")
    return relate_result[0]

relate_url = get_related_search(url)
print(relate_url)
Run Code Online (Sandbox Code Playgroud)

结果:markup_type=markup_type)) p class="_e4b"}{a href="/search?...a}{/p}

我现在想抓取 href 结果。我不确定下一步会是什么。谢谢您的帮助。

注意:我用 {} 替换了 <>,因为它没有显示为 html 脚本

python selenium webdriver beautifulsoup bs4

3
推荐指数
1
解决办法
1331
查看次数

正则表达式[0-9]和[0-9.]之间的差异

我刚开始研究正则表达式,并想知道以下内容之间的区别:

def test():
    string = "He was 75 in the 1985sdfdhs 45"
    y = re.findall('[0-9]+', string)
    print(y)

test()
Run Code Online (Sandbox Code Playgroud)

还有这个

def test2():
    string = "He was 75 in the 1985sdfdhs 45"
    y = re.findall('[0-9.]+', string)
    print(y)

test2()
Run Code Online (Sandbox Code Playgroud)

据我所知,"." 匹配任何字符,所以我认为test2的输出将等于['75','1985sdfdhs','45'],相反它们都是['75','1985','45'].只想弄清楚这里发生了什么.谢谢.

python regex

3
推荐指数
1
解决办法
2922
查看次数

Visual Studio For Mac 调试单元测试

我刚刚为 Mac 下载了 VS 2019。控制台项目调试工作正常,达到断点。如果我尝试调试 MSTest 或 NUnit 测试项目,断点将被忽略,没有错误消息。

我尝试更改选项,处于调试模式,尝试重新启动并创建新项目。我已经从 nuget 下载了 MSTest.TestFramework 和 MSTest.TestAdapter。这些都没有奏效。

关于如何解决这个问题的任何想法?

c# debugging visual-studio-debugging visual-studio-mac

3
推荐指数
1
解决办法
3577
查看次数

VBA CountA错误1004

我一直收到错误1004.我不知道如何声明我的对象以避免此错误:

Sub DeleteBlank()

    Dim wb As Workbook
    Set wb = ActiveWorkbook

    Dim ws As Worksheet
    Set ws = wb.Worksheets("Sheet1")
    ws.Activate

    'Delete Blank Columns
    For col = 1 To 4
        If WorksheetFunction.CountA(ws.Columns(i)) = 0 Then
            ws.Columns.Delete
        End If
    Next col


End Sub
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

2
推荐指数
1
解决办法
115
查看次数

WebElement 没有属性 w3c

我试图在给定用户输入的情况下浏览 Instagram 页面。我能够进入该页面。页面加载,然后找到类,然后代码中断。这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys 
from  bs4 import BeautifulSoup
import urllib.request, urllib.parse, urllib.error
import time

def get_posts(tag, user_count):

    '''Getting html of page to be scrape for
    hrefs that will get me the user names'''

    print("getting page")
    url = "https://www.instagram.com/explore/tags/" + tag + "/"
    try:
        driver = webdriver.Chrome()
        driver.get(url)
        print("successfully requested site")
    except:
        print("Unable to reach site")
        quit()

    browser = driver.find_element_by_class_name('_si7dy')
    actions = ActionChains(browser)
    for i in range(user_count):
        actions = actions.send_keys(Keys.TAB) …
Run Code Online (Sandbox Code Playgroud)

python selenium action python-3.x selenium-webdriver

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

MVVM按钮可见性

我有一个在我的ViewModel构造函数中设置为隐藏的按钮.当用户点击某个项目时,该按钮应该可见.我的断点和消息框显示可见性的值正在变为"可见"所以我不确定我在绑定中缺少什么.

XAML:

    <Button  
        Grid.Column="0"
        Grid.Row="2"
        HorizontalAlignment="Left" 
        Margin="105,22,0,21" 
        Style="{StaticResource MetroButton}" 
        Width="90" 
        Height="57" 
        Click="btn_Update_Click" 
        RenderTransformOrigin="0.49,0.287"
        Visibility="{Binding Btn_Update_Visibility, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
        <TextBlock Text="Update Request" TextWrapping="Wrap" TextAlignment="Center"/>
    </Button>
Run Code Online (Sandbox Code Playgroud)

视图模型:

项目用户可以选择:

private DataRowView select_request;
public DataRowView Select_Request
{
    get { return select_request; }
    set
    {
        select_request = value;
        OnPropertyChanged("Select_Request");

        //Get the Check Request ID
        OnSelect_RequestChange();

        //Make Update Button Visible
        OnSelect_Row();
    }
}
Run Code Online (Sandbox Code Playgroud)

在XAML中绑定可见性的价值

private string btn_update_visiblity;
public string Btn_Update_Visibility
{
    get { return btn_update_visiblity; }
    set
    {
        btn_update_visiblity = value;
        OnPropertyChanged("Btn_Update_Visibility");
    }
}
Run Code Online (Sandbox Code Playgroud)

用户选择行时调用的方法

public void OnSelect_Row() …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml mvvm

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