[英]Python requests lib doesn't work with LinkedIn
Sample code: 样例代码:
import requests
print requests.get("https://www.linkedin.com/")
I get: <Response [200]>
我得到: <Response [200]>
Simple curl request does work: 简单的curl请求确实起作用:
curl "https://www.linkedin.com/"
If you get <Response [200]>
that means that it worked properly. 如果得到<Response [200]>
,则表明它正常工作。 You should refer to the documentation for unpacking this Response
object to get the data inside of it. 您应该参考文档来解压缩此Response
对象以获取其中的数据。
Eg: 例如:
>>> r = requests.get('https://linkedin.com/')
>>> r.text
'<!DOCTYPE html> ...'
The requests.get() function returns a Response object that contains attributes about the status_code, headers, and content: request.get()函数返回一个Response对象,其中包含有关status_code,标头和内容的属性:
[In]: type(requests.get("https://www.linkedin.com/")
[Out]: <class 'requests.models.Response'>
. [Out]: <class 'requests.models.Response'>
。
I would recommend saving the returned Response into a variable: 我建议将返回的响应保存到变量中:
response = requests.get("https://www.linkedin.com/")
Then you can access the contents of the Response using response.json()
if it is a JSON file or response.text
if it is an html page. 然后,您可以使用访问响应的内容response.json()
如果它是一个JSON文件或response.text
如果它是一个HTML页面。
In your use case, response.text
should return the same thing as curl "https://www.linkedin.com/"
. 在您的用例中, response.text
应该返回与curl "https://www.linkedin.com/"
相同的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.