【发布时间】:2018-01-01 11:59:04
【问题描述】:
我已经在 python 中编写了一些脚本来抓取该网页中可用的下一页链接,该网页目前运行良好。这个刮刀的唯一问题是它不能摆脱重复的链接。希望有人能帮我完成这个。我试过了:
import requests
from lxml import html
page_link = "https://yts.ag/browse-movies"
def nextpage_links(main_link):
response = requests.get(main_link).text
tree = html.fromstring(response)
for item in tree.cssselect('ul.tsc_pagination a'):
if "page" in item.attrib["href"]:
print(item.attrib["href"])
nextpage_links(page_link)
这是我得到的部分图像:
【问题讨论】:
-
你做一个集合,添加所有处理的链接,并在处理之前检查链接是否已经存在。
标签: python python-3.x web-scraping css-selectors web-crawler