1
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.

enter image description here

0m3r
  • 12,286
  • 15
  • 35
  • 71
Kipkurui
  • 43
  • 10

1 Answers1

0

Example

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))

Prints out

New Longines Master Collection Automatic 40mm White Men's Watch L2.909.4.78.3
0m3r
  • 12,286
  • 15
  • 35
  • 71