I want to get this kind of content by scraping website.
I was trying to use this code
import lxml.html
import lxml.etree as et
import urllib.request
import urllib.parse
url = ""
response = urllib.request.urlopen(url)
root = et.parse(response)
rows = root.xpath("//table[@class='viewport']//tr")
for row in rows:
cells = row.xpath("td")
print("Title: {}".format(cells[0].text_content()))
For me the output is always the same
Title: Dt00 I.img Pes 2013.rar
Title: Dt00 I.img Pes 2013.rar
Title: Dt00 I.img Pes 2013.rar
Title: Dt00 I.img Pes 2013.rar
Title: Dt00 I.img Pes 2013.rar
I wanted to get this content
Title: Dt00 I.img Pes 2013.rar
Title: Dt00 E.img Pes 2013.rar
Title: Dt00 E.img Pes 2013.rar
Title: Dt00 E.img Pes 2013.rar
Title: Dt00 E.img Pes 2013.rar
I need to scrape the tables but i want to store the table content not the url.
A:
Here's the solution. I used BeautifulSoup.
from bs4 import BeautifulSoup
import requests
import urllib.request
url = ""
response = requests.get(url)
soup = BeautifulSoup(response.content,'lxml')
tables = soup.find_all('table', attrs={"class": "viewport"})
for table in tables:
print(table.contents[0])
Result:
Dt00 I.img Pes 2013.rar
Dt00 E.img Pes 2013.rar
Dt00 E.img Pes 2013.rar
Dt00 E.img Pes 2013.rar
I be359ba680
Related links:
Comentários