We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
def get_one_page(url): try: headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36' } response = requests.get(url, headers=headers) if response.status_code == 200: response.close() return response.text return None except RequestException: return None
The text was updated successfully, but these errors were encountered:
不加会怎样?
Sorry, something went wrong.
加上这个response.close()爬取速度会明显加快,不加的话,你的request请求不会立即关闭,容易被网站侦测出来,可以对比一下试试
可不可以用上下文方式写,with requrests.get这种的
No branches or pull requests
def get_one_page(url):
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
response.close()
return response.text
return None
except RequestException:
return None
The text was updated successfully, but these errors were encountered: