代码之家  ›  专栏  ›  技术社区  ›  Kamikaze_goldfish

请求html页面与浏览器不同

  •  0
  • Kamikaze_goldfish  · 技术社区  · 8 年前

    Page I want to scrape

    page = requests.get('https://www.yellowpages.com/new-orleans-la/mip/upperline-restaurant-526381149?lid=1001797484770')
    soup = BeautifulSoup(page.text, 'lxml')
    # I am trying to find this class 'sales-info' but it isn't in the html when rendered.
    business_name = soup.find('div', class_='sale-info')
    print(business_name)
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   sniperd Ali Ahmed    8 年前

    看起来只是个小o型, sale-info 应该是 sales-info (注意第二个 s公司 )试试这个:

    import requests
    from bs4 import BeautifulSoup
    
    page = requests.get('https://www.yellowpages.com/new-orleans-la/mip/upperline-restaurant-526381149?lid=1001797484770')
    soup = BeautifulSoup(page.text, 'html.parser')
    # I am trying to find this class 'sales-info' but it isn't in the html when rendered.
    business_name = soup.find('div', class_='sales-info')
    print(business_name)
    

    结果:

    <div class="sales-info"><h1>Upperline Restaurant</h1></div>