【问题标题】:selecting itemTitle in h1- beautifulsoup在 h1-beautifulsoup 中选择 itemTitle
【发布时间】:2020-05-04 22:13:42
【问题描述】:
import requests
from bs4 import BeautifulSoup


def get_page(url):
    response = requests.get(url)

if not response.ok:
    print('Server Responded: ', response.status_code)
else:
    soup = BeautifulSoup(response.text, 'lxml')
    return soup

def get_detail_data(soup):
    #price
    #item

    h1 = soup.find('h1', id='itemTitle')
    print(h1)


def main():
    url = "https://www.ebay.com/itm/New-Longines-Master-Collection-Automatic-40mm-White-Mens-Watch-L2-909-4-78-3/383525040495?hash=item594bdfb16f:g:vdIAAOSwytheqbKu"

    get_detail_data(get_page(url))



if __name__ == '__main__':
     main()

hi please help me with how I can select the item name on e-bay. The item name is the title of the watch. I managed to get to the then to itemTitle.

【问题讨论】:

    标签: python html python-3.x beautifulsoup python-requests


    【解决方案1】:

    例子

    import requests
    from bs4 import BeautifulSoup
    
    
    def get_page(url):
        response = requests.get(url=url)
        if not response.ok:
            print('Server Responded: ', response.status_code)
        else:
            soup = BeautifulSoup(response.text, features='html.parser')
            return soup
    
    
    def get_detail_data(soup):
        h1 = soup.select("span.g-hdn")[0]
        print(h1.next_sibling)
        return h1
    
    
    if __name__ == "__main__":
        url = "https://www.ebay.com/itm/New-Longines-Master-Collection-Automatic-40mm-White-Mens-Watch-L2-909-4-78-3/383525040495?hash=item594bdfb16f:g:vdIAAOSwytheqbKu"
        get_detail_data(get_page(url))
    

    打印出来

    New Longines Master Collection Automatic 40mm White Men's Watch L2.909.4.78.3
    

    【讨论】:

    • 如果我想要“新款浪琴表大师系列自动 40 毫米白色男士手表 L2.909.4.78.3”怎么办?
    • 我收到“关于新款浪琴表大师系列自动 40 毫米白色男士手表 L2.909.4.78.3 的详细信息。”如何提取“New Longines Master Collection Automatic 40mm White Men's Watch L2.909.4.78.3.”
    • 对不起,我有点忙 - 查看更新的答案-
    • 您可以推荐哪些资源来提高我的技能?
    • stackoverflow.com/a/61467369/4539709 - 看到这个答案它有链接@H-petes让我知道
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 2022-01-08
    • 2018-02-21
    • 1970-01-01
    相关资源
    最近更新 更多