You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
response = requests.get(url, headers=headers)
list = xpath_with_response(response)
for item in list:
title = item.xpath('./a/text()')[0]
link = item.xpath('./a/@href')[0]
print(f"标题: {title}, 链接: {link}")
使用示例
if name == "main":
cookie = first_cookie()
print(f"提取的Cookie: {cookie}")
if cookie:
request_with_cookie(cookie)
else:
print("未能提取到Cookie")
The text was updated successfully, but these errors were encountered:
import requests
import re
url = 'https://jytyj.shangqiu.gov.cn/zwgk/fdzdgknr/zfcg31sqsjytyj/zbgg31sqsjytyj_2'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
}
def first_cookie():
"""
获取页面响应中JavaScript设置的cookie
"""
res = requests.get(url, headers=headers)
def xpath_with_response(res):
"""
使用XPath解析响应内容
"""
from lxml import etree
def request_with_cookie(cookie):
"""
使用提取的cookie进行请求
"""
headers = {
'Cookie': cookie,
}
使用示例
if name == "main":
cookie = first_cookie()
print(f"提取的Cookie: {cookie}")
if cookie:
request_with_cookie(cookie)
else:
print("未能提取到Cookie")
The text was updated successfully, but these errors were encountered: