kingmaster56
New Member
I want to scraping the id on a source code of a page with python but not all link just code ( sorry for my english i use google translate ) thank you so much
import requests
import re
from lxml import html
url = 'http://your-url-here/'
resp = requests.get(url)
doc = html.fromstring(resp.text)
href = doc.xpath('string((//span[@class = "dato"]/a[contains(@href, "imdb.com/title/")])[1]/@href)')
regex = re.search(r'imdb\.com/title/(?P<id>tt\d+)', href)
imdb_id = regex.group('id') if regex is not None else 'NOT_FOUND'
print(imdb_id)
import requests
import re
url = 'http://your-url-here/'
resp = requests.get(url)
regex = re.search(r'imdb\.com/title/(?P<id>tt\d+)', resp.text, re.M)
imdb_id = regex.group('id') if regex is not None else 'NOT_FOUND'
print(imdb_id)