johnnyb 发表于 2020-7-16 14:47:37

利用Xpath爬取dytt8 全部电影名字. 看思路就好

本帖最后由 johnnyb 于 2020-7-16 14:51 编辑

特别鸣谢.5群 叙白 大佬给的提示..
import requests
from lxml import etree

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
}
url = 'https://www.ygdy8.net/html/gndy/dyzz/list_23_1.html'
for i in range(1, 219):
    new_url = 'https://www.ygdy8.net/html/gndy/dyzz/list_23_'+str(i)+'.html'
    response = requests.get(url=url, headers=headers)
    response.raise_for_status()
    response.encoding = 'gbk'
    r_text = response.text
    tree = etree.HTML(r_text)
    r = tree.xpath('//div[@class="co_content8"]/ul//a[@class="ulink"]')
    for a in r:
      print(a.text)
页: [1]
查看完整版本: 利用Xpath爬取dytt8 全部电影名字. 看思路就好