Created
June 1, 2019 21:55
-
-
Save moonzlo/9aed0eaa57474e66dbb447bd3a80424d to your computer and use it in GitHub Desktop.
lxml example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tree = etree.HTML(html) | |
| for block in tree.xpath("//div[@class='product']"): | |
| img = block.xpath("//img/@src")[0] | |
| name = block.xpath("//tr[@class='name']")[0].text | |
| id = block.xpath("//tr[@class='id']")[0].text |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Аналогичен
soup = BeautifulSoup(page) # page - скачиваем страницу и отдаем ее
for item in soup.findAll("div", {"class": "product"}):
img = item.find("img")["src"]
name = soup.find("tr", {"class": "name"})
id = soup.find("tr", {"class": "id"})