【问题标题】:Is there anyway to scrape specific information无论如何要抓取特定信息
【发布时间】:2019-11-26 23:35:36
【问题描述】:

如何获取位于 Base Url 中的“star_recom”信息?

Star_recom 的类型是数字(例如 49%),您可以在 BaseUrl 中看到。

请检查代码并告诉我是否有任何问题。

BaseUrl = 'https://www.jobplanet.co.kr/companies/90364/'
req = requests.get(BaseUrl)
soup = BeautifulSoup(req.text,'html.parser')
body = soup.find("div",{"class":"body_wrap"})
sbody= body.find("dl", {"class":"rate_bar_set"})


star_recom = body.find('div', class_='pie1').find('span', class_='txt_point').text.strip() 

【问题讨论】:

    标签: web-scraping python-requests web-crawler


    【解决方案1】:

    您的代码是正确的,但它不会返回任何内容,因为您尝试抓取的数据是由正文中的 JavaScript 函数编写的。

    <div class="review_stats-pagination"></div>
    <script>
      ;(function($){
        // Fill animations
    
    
        // Dummy data
        var data = [
          {label:'직원의 기업 추천율',val : 0.85},
          {label:'직원이 전망하는 성장 가능성',val : 0.81},
          {label:'이 기업의 CEO 지지율',val : 0.93 }
        ];
    

    你可以试试:

    import re
    BaseUrl = 'https://www.jobplanet.co.kr/companies/90364/'
    req = requests.get(BaseUrl).text
    
    # extract the values as it is in the dom
    spans = re.findall( r',val\s*:\s*(.*?)}', req )
    print(spans)
    

    输出:

    ['0.85', '0.81', '0.93 ']
    

    如果你想要完全相同的信息:

    # convert it to look like the data displayed on the html
    text_as_website = ['{}%'.format(int(float(span) * 100)) for span in spans]
    print(text_as_website)
    

    输出:

    ['85%', '81%', '93%']
    

    【讨论】:

      猜你喜欢
      • 2017-05-09
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多