首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python使用BeautifulSoup从所有子页面中删除相同的项

Python使用BeautifulSoup从所有子页面中删除相同的项
EN

Stack Overflow用户
提问于 2022-09-10 14:46:14
回答 1查看 55关注 0票数 0

我正试图从每个子页中取消“工资”。对于其中一个子页面,我要复制soup =BeautifulSoup(requests.get('url_of_job').text的特定内容。我将soup内容复制到一个word文件中,并将围绕salary的内容切片,然后在这里复制。复制所有文本超过了这里的限制。

汤=

代码语言:javascript
运行
复制
代码语言:javascript
运行
复制
    </style>

代码语言:javascript
运行
复制
    {
代码语言:javascript
运行
复制
        "@context"          :   "https://schema.org",
代码语言:javascript
运行
复制
        "@type"             :   "Organization",
代码语言:javascript
运行
复制
        "url"               :   "https://www.higheredjobs.com",
代码语言:javascript
运行
复制
        "logo"              :   "https://www.higheredjobs.com/assets/hej/img/HEJ_Logo_2c.png",
代码语言:javascript
运行
复制
        "potentialAction"   :   {
代码语言:javascript
运行
复制
                                    "@type"         : "SearchAction",
代码语言:javascript
运行
复制
                                    "target"        : "https://www.higheredjobs.com/search/advance_action.cfm?Keyword={Keyword}",
代码语言:javascript
运行
复制
                                    "query-input"   : "required name=Keyword"
代码语言:javascript
运行
复制
                                }
代码语言:javascript
运行
复制
    }
代码语言:javascript
运行
复制
    </script>

代码语言:javascript
运行
复制
                {
代码语言:javascript
运行
复制
                    "@context"              :   "http://schema.org/",
代码语言:javascript
运行
复制
                    "@type"                 :   "JobPosting",
代码语言:javascript
运行
复制
                    "industry"              :   ["Academic/Education","Education"],
代码语言:javascript
运行
复制
                    "title"                 :   "Assistant Professor of Engineering F99507",
代码语言:javascript
运行
复制
                    "description"           :   "&lt;p&gt;&lt;strong&gt;&lt;u&gt;MCNEESE STATE UNIVERSITY&lt;/u&gt;&lt;/strong&gt;&lt;strong&gt; invites applicants for the position of Assistant Professor of Engineering.&lt;/strong&gt;&lt;/p&gt;

DEPARTMENT:工程与计算机科学 ;

POSITION信息:这是一个全职的,9个月的,未分类的,终身职位.任命于2023年1月开始。

POSITION数:F 99507

SALARY:$76,000

REPORTING权威:工程和计算机科学系主任

POSITION职责/职责:工程助理教授负责与教学课程、指导学生和进行研究有关的职能。这位助理教授将与工程和计算机科学系的教职员工密切合作。

<强>要求/优先资格:

所需 ;

电气工程18小时工程

  • Master

电力工程

  • Experience &li;/li>

首选

电气工程

  • PhD

DEADLINE:位置将一直打开,直到填满为止。 ;

APPLICATION过程和材料:申请程序要求申请人和必须填写电子申请并上传所需文件,如下所示:

申请

  • Letter (求职信)

  • 简历/Vitae

  • Three专业参考资料(包括:姓名、电话号码和电子邮件地址)

  • Unofficial转录本

TO申请此职位空缺,请点击广告顶部的“强”和“强”按钮完成电子申请,该职位可用于此职位空缺以及未来的工作机会。申请者有责任检查其申请状态,以确定他们在招聘过程中的位置。进一步的状态消息信息位于“当前就业机会”页面的“信息”部分。

ALL提供的工作取决于犯罪背景调查的成功结果,如果适用的话,还将收到成绩单(S)。

If您对此招聘有疑问,请与人力资源联络部联系:

Kim Dronett at kdronett@mcneese.edu或(337) 475-5413.

代码语言:javascript
运行
复制
                    "datePosted"            :   "2022-09-02 09:48:23.527",
代码语言:javascript
运行
复制
                    "validThrough"          :   "2023-03-01 23:59:59.9",
代码语言:javascript
运行
复制
                    "baseSalary"            :   {
代码语言:javascript
运行
复制
                                                "@type"         :   "MonetaryAmount",
代码语言:javascript
运行
复制
                                                "currency"      :   "USD",
代码语言:javascript
运行
复制
                                                "value"         :   {
代码语言:javascript
运行
复制
                                                                            "@type"     :   "QuantitativeValue",
代码语言:javascript
运行
复制
                                                                            "value" :   "76,000.00",
代码语言:javascript
运行
复制
                                                                            "unitText"  :   "YEAR"
代码语言:javascript
运行
复制
                                                                        }
代码语言:javascript
运行
复制
                                                },
代码语言:javascript
运行
复制
                    "hiringOrganization"    :   {
代码语言:javascript
运行
复制
                                                    "@type"     :   "Organization",
代码语言:javascript
运行
复制
                                                        "id"        :   "http://www.mcneese.edu",
代码语言:javascript
运行
复制
                                                        "url"       :   "http://www.mcneese.edu",
代码语言:javascript
运行
复制
                                                    "name"      :   "McNeese State University"
代码语言:javascript
运行
复制
                                                },
代码语言:javascript
运行
复制
                    "jobLocation"           :   {
代码语言:javascript
运行
复制
                                                    "@type"     :   "Place",
代码语言:javascript
运行
复制
                                                    "address"   :   {
代码语言:javascript
运行
复制
                                                                        "@type"             :   "PostalAddress",
代码语言:javascript
运行
复制
                                                                        "addressLocality"   :   "Lake Charles",
代码语言:javascript
运行
复制
                                                                        "addressRegion"     :   "LA",
代码语言:javascript
运行
复制
                                                                        "addressCountry"    :   "US"
代码语言:javascript
运行
复制
                                                                    }
代码语言:javascript
运行
复制
                                                },
代码语言:javascript
运行
复制
                    "employmentType"        :   "FULL_TIME",
代码语言:javascript
运行
复制
                    "image"                 :   "https://www.higheredjobs.com/assets/hej/img/HEJ_Logo_2c.png"
代码语言:javascript
运行
复制
                }
代码语言:javascript
运行
复制
            </script>

代码语言:javascript
运行
复制
            @media (min-width: 768px) { /*menus work different at XS*/
代码语言:javascript
运行
复制
                HEADER ul.nav li.dropdown:hover > .arrow,
代码语言:javascript
运行
复制
                HEADER ul.nav li.dropdown:hover > ul.dropdown-menu {
代码语言:javascript
运行
复制
                    display: block;
代码语言:javascript
运行
复制
                }
代码语言:javascript
运行
复制
            }
代码语言:javascript
运行
复制
        </style>

类型:

代码语言:javascript
运行
复制
    Full-Time
代码语言:javascript
运行
复制
    <br/>

薪金:

代码语言:javascript
运行
复制
        $76,000.00 USD Per Year
代码语言:javascript
运行
复制
        <br/>

张贴:

代码语言:javascript
运行
复制
        09/02/2022 
代码语言:javascript
运行
复制
        <br/>

应交申请:

代码语言:javascript
运行
复制
        Open Until Filled
代码语言:javascript
运行
复制
        <br/>

类别:

代码语言:javascript
运行
复制
            Electrical Engineering
代码语言:javascript
运行
复制
        </a>

工程部。系:工程及电脑科学职位资讯:

这是一个全职的,9个月的,非机密的,终身职位。这项任命于2023年1月开始。位置

编号: F99507工资:76,000美元报告机构:工程部主管

和计算机科学职位职责:工程助理教授负责

与教学课程相关的职能,为学生提供咨询,并进行研究。这位助理教授将与教师密切合作。

以及工程和计算机科学系的工作人员。所需/优先资格:

工程学

会一直打开直到被填满。

代码语言:javascript
运行
复制

我的代码:

代码语言:javascript
运行
复制
'salary': soup.select_one('strong:-soup-contains("Salary:")').get_text(strip=True)

目前的解决办法:

代码语言:javascript
运行
复制
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.

预期解决办法:

代码语言:javascript
运行
复制
'salary':$76,000.00 USD Per Year
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-10 15:06:26

以下是允许您以编程方式访问该作业信息的解决方案:

代码语言:javascript
运行
复制
from bs4 import BeautifulSoup
import json
html = '''
<script type="application/ld+json">
                    {
                        "@context"              :   "http://schema.org/",
                        "@type"                 :   "JobPosting",
                        "industry"              :   ["Academic/Education","Education"],
                        "title"                 :   "Assistant Professor of Engineering F99507",
                        "description"           :   "&lt;p&gt;&lt;strong&gt;&lt;u&gt;MCNEESE STATE UNIVERSITY&lt;/u&gt;&lt;/strong&gt;&lt;strong&gt; invites applicants for the position of Assistant Professor of Engineering.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DEPARTMENT: &lt;/strong&gt;Engineering and Computer Science&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;POSITION INFORMATION: &lt;/strong&gt;This is a full-time, 9-month, unclassified, tenure-track position. The appointment begins in January 2023.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;POSITION NUMBER: &lt;/strong&gt;F99507&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SALARY: &lt;/strong&gt;$76,000&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;REPORTING AUTHORITY: &lt;/strong&gt;Department Head of Engineering and Computer Science&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;POSITION DUTIES/RESPONSIBILITIES: &lt;/strong&gt;The Assistant Professor of Engineering is responsible for functions related to teaching courses, advising students, and conducting research. The assistant professor will work closely with faculty and staff in the Department of Engineering and Computer Science.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;REQUIRED/PREFERRED QUALIFICATIONS: &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Required&lt;/u&gt;:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Master of Engineering with 18 hours in Electrical Engineering&lt;/li&gt;
&lt;li&gt;Experience with Power Engineering&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;u&gt;Preferred&lt;/u&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;PhD in Electrical Engineering&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;DEADLINE: &lt;/strong&gt;Position will remain open until filled.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;APPLICATION PROCESS AND MATERIALS: &lt;/strong&gt;For the application process, applicants are required and &lt;strong&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;MUST&lt;/span&gt;&lt;/strong&gt; complete an electronic application and upload required documents listed below:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Letter of Application (Cover Letter)&lt;/li&gt;
&lt;li&gt;Resume/Vitae&lt;/li&gt;
&lt;li&gt;Three Professional References (include: name, phone number, and e-mail address)&lt;/li&gt;
&lt;li&gt;Unofficial Transcripts&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;TO APPLY FOR THIS VACANCY, &lt;/strong&gt;click on the &lt;strong&gt;&amp;ldquo;APPLY&amp;rdquo;&lt;/strong&gt; button at the top of advertisement to complete the electronic application, which can be used for this vacancy as well as future job opportunities. Applicants are responsible for checking the status of their application to determine where they are in the recruitment process. Further status message information is located under the Information section of the Current Job Opportunities page.&lt;/p&gt;
&lt;p&gt;ALL JOB OFFERS ARE CONTINGENT UPON THE SUCCESSFUL RESULT OF A CRIMINAL BACKGROUND CHECK AND RECEIPT OF TRANSCRIPT(S) IF APPLICABLE.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If you have questions regarding this recruitment, please contact the HR Liaison:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Kim Dronett at &lt;a rel=&quot;noopener&quot; href=&quot;kdronett@mcneese.edu&quot; target=&quot;_blank&quot;&gt;kdronett@mcneese.edu&lt;/a&gt; or (337) 475-5413.&lt;/p&gt;",
                        "datePosted"            :   "2022-09-02 09:48:23.527",

                    
                    
                        "validThrough"          :   "2023-03-01 23:59:59.9",
                    
                        "baseSalary"            :   {
                                                    "@type"         :   "MonetaryAmount",
                                                    "currency"      :   "USD",
                                                    "value"         :   {
                                                                                "@type"     :   "QuantitativeValue",
                                                                            
                                                                                "value" :   "76,000.00",
                                                                                                                                                        
                                                                                "unitText"  :   "YEAR"
                                                                            }
                                                    },
                                
                        "hiringOrganization"    :   {
                                                        "@type"     :   "Organization",
                                                        
                                                            "id"        :   "http://www.mcneese.edu",
                                                            "url"       :   "http://www.mcneese.edu",
                                                                                                            
                                                        "name"      :   "McNeese State University"
                                                    },
                        "jobLocation"           :   {
                                                        "@type"     :   "Place",
                                                        "address"   :   {
                                                                            "@type"             :   "PostalAddress",
                                                                            "addressLocality"   :   "Lake Charles",
                                                                            "addressRegion"     :   "LA",
                                                                            "addressCountry"    :   "US"
                                                                        }
                                                    },
                    

                        "employmentType"        :   "FULL_TIME",
                        "image"                 :   "https://www.higheredjobs.com/assets/hej/img/HEJ_Logo_2c.png"
                    }
                </script>
<noscript>
<style type="text/css">
                @media (min-width: 768px) { /*menus work different at XS*/
                    HEADER ul.nav li.dropdown:hover > .arrow,
                    HEADER ul.nav li.dropdown:hover > ul.dropdown-menu {
                        display: block;
                    }
                }
            </style>
</noscript>

<div class="col-6">
<h5>Resources</h5>
<ul>
<li><a href="/career/">Career Resources</a></li>
<li><a href="/salary/">Salary Data</a></li>
<li><a href="/career/resumes.cfm">Job Search Tips</a></li>
<li><a href="/career/ResumeService.cfm">Resume/CV Writing<br/> Service</a></li>
<li><a href="/articles/DiversityResources.cfm">Diversity Resources</a></li>
<li><a href="/career/SiteListings.cfm">Search Firms</a></li>
</ul>
</div>
</div>
</li>
</ul>
</li>
<li class="nav-item dropdown js-emplogin">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="/employers/">


<div class="" id="jobAttrib">
<div class="job-info">
<strong>Type:</strong>
        Full-Time
        <br/>
<strong>Salary:</strong>
            $76,000.00 USD Per Year
            <br/>
<strong>Posted:</strong>
            09/02/2022 
            <br/>
<strong>Application Due:</strong>
            Open Until Filled
            <br/>
<strong>Category:</strong>
<a class="job-cat" href="/faculty/search.cfm?JobCat=117">
                Electrical Engineering
            </a>
<br/>
</div>
</div>

</div>
</div>
<div id="jobDesc">
<p><strong><u>MCNEESE STATE UNIVERSITY</u></strong><strong> invites applicants for the position of Assistant Professor of
Engineering.</strong></p> <p><strong>DEPARTMENT: </strong>Engineering and Computer Science </p> <p><strong>POSITION INFORMATION:
</strong>This is a full-time, 9-month, unclassified, tenure-track position. The appointment begins in January 2023.</p> <p><strong>POSITION
NUMBER: </strong>F99507</p> <p><strong>SALARY: </strong>$76,000</p> <p><strong>REPORTING AUTHORITY: </strong>Department Head of Engineering
and Computer Science</p> <p><strong>POSITION DUTIES/RESPONSIBILITIES: </strong>The Assistant Professor of Engineering is responsible for
functions related to teaching courses, advising students, and conducting research. The assistant professor will work closely with faculty
and staff in the Department of Engineering and Computer Science.</p> <p><strong>REQUIRED/PREFERRED QUALIFICATIONS: </strong></p>
<p><u>Required</u>: </p> <ul>
<li>Master of Engineering with 18 hours in Electrical Engineering</li>
<li>Experience with Power
Engineering</li>
</ul> <p><u>Preferred</u>:</p> <ul>
<li>PhD in Electrical Engineering</li>
</ul> <p><strong>DEADLINE: </strong>Position
will remain open until filled.   
'''
soup = BeautifulSoup(html, 'html.parser')
script = soup.select_one('script[type="application/ld+json"]')
# print(script.contents[0])
json_obj = json.loads(script.contents[0], strict=False)
print(json_obj['industry'])
print(json_obj['baseSalary']['value']['value'])
#### and here is a solution to find salary in actual html, not in script tag ###
salary_parent_div = soup.select_one('div.job-info')
salary = salary_parent_div.find('strong', string='Salary:').next_sibling
print(salary.strip())

这将在终端打印:

代码语言:javascript
运行
复制
['Academic/Education', 'Education']
76,000.00
$76,000.00 USD Per Year

当然,您可以深入研究json对象,并选择有关作业的更多细节。BeautifulSoup文档:https://beautiful-soup-4.readthedocs.io/en/latest/index.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73672732

复制
相关文章

相似问题

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