小编Rev*_*har的帖子

使用beautifulSoup,Python在h3和div标签中刮取文本

我没有使用python,BeautifulSoup,Selenium等的经验,但是我很想从网站上抓取数据并将其存储为csv文件。我需要的单个数据样本编码如下(单个数据行)。

<div class="box effect">
<div class="row">
<div class="col-lg-10">
    <h3>HEADING</h3>
        <div><i class="fa user"></i>&nbsp;&nbsp;NAME</div>
        <div><i class="fa phone"></i>&nbsp;&nbsp;MOBILE</div>
        <div><i class="fa mobile-phone fa-2"></i>&nbsp;&nbsp;&nbsp;NUMBER</div>
        <div><i class="fa address"></i>&nbsp;&nbsp;&nbsp;XYZ_ADDRESS</div>
    <div class="space">&nbsp;</div>

<div style="padding:10px;padding-left:0px;"><a class="btn btn-primary btn-sm" href="www.link_to_another_page.com"><i class="fa search-plus"></i> &nbsp;more info</a></div>

</div>
<div class="col-lg-2">

</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我需要的输出是 Heading,NAME,MOBILE,NUMBER,XYZ_ADDRESS

我发现这些数据没有ID或类别,但仍以通用文本形式出现在网站中。为此,我分别尝试使用BeautifulSoup和Python Selenium,在这两种方法中我都被困于提取方法,因为我没有看到任何教程,指导我从这些方法和标签中提取文本

我的代码使用BeautifulSoup

import urllib2
from bs4 import BeautifulSoup
import requests
import csv

MAX = 2

'''with open("lg.csv", "a") as f:
  w=csv.writer(f)'''
##for i in range(1,MAX+1)
url="http://www.example_site.com"

page=requests.get(url)
soup = BeautifulSoup(page.content,"html.parser")

for h in soup.find_all('h3'):
    print(h.get('h3'))
Run Code Online (Sandbox Code Playgroud)

我的硒代码

import …
Run Code Online (Sandbox Code Playgroud)

html python selenium beautifulsoup web-crawler

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

"***堆栈粉碎检测***:./a.out终止Aborted(核心转储)" - 数组inserion

我在下面的代码中通过Internet在数组中插入一个元素.我的问题是,如何在第一次插入时增加数组的大小,并在每次执行打印时打印垃圾.我也很渴望获取有关我得到的错误的详细信息.

代码是

#include <stdio.h>
void main() 
{
    int k = 3, n = 5, i = 0, j = n;
    int LA[] = {1,3,5,7,8};
    printf("The original array elements are :\n");
    for(i = 0; i<n; i++) {
        printf("%d ",LA[i]);
    }
    n = n + 1;
    while( j >= k){
        LA[j+1] = LA[j];
        j = j - 1;
    }
    LA[k] = 10;
    printf("\nThe array elements after insertion1 :\n");
    for(i = 0; i<n; i++) {
        printf("%d ",LA[i]);
    }
    n = n + 1; …
Run Code Online (Sandbox Code Playgroud)

arrays insertion

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

标签 统计

arrays ×1

beautifulsoup ×1

html ×1

insertion ×1

python ×1

selenium ×1

web-crawler ×1