Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 xpath 与 css 选择器 #7

Open
Chou007 opened this issue Aug 17, 2020 · 0 comments
Open

关于 xpath 与 css 选择器 #7

Chou007 opened this issue Aug 17, 2020 · 0 comments

Comments

@Chou007
Copy link

Chou007 commented Aug 17, 2020

第四章 信息校验与反爬虫 postman 示例

cookie 反爬虫

`import requests
from lxml import etree

url = 'http://www.porters.vip/verify/cookie/content.html'
resp = requests.get(url)
if resp.status_code == 200:
html = etree.HTML(resp.text)
res = html.cssselect('.page-header h1') #①
print(res)
else:
print('This request is fail.')`

① 处 使用的是css选择器,需要指定cookie才有内容返回,但我没有加cookie,使用xpath(改为 html.xpath('//h1/text()') ) 后就爬取到了主题,为什么?难道 xpath 与 css 选择器在重定向上有原理差异?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant