马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 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)
|