When you run the following code on Google:
response.ip_address
Her values equal to:
IPv4Address('79.127.127.87')
But the expected answer is as follows:
'79.127.127.87'
How to get this answer?
CodePudding user response:
Just use str():
scrapy shell
In [1]: url='https://httpbin.org/'
In [2]: req = scrapy.Request(url=url)
In [3]: fetch(req)
[scrapy.core.engine] INFO: Spider opened
[scrapy.core.engine] DEBUG: Crawled (200) <GET https://httpbin.org/> (referer: None)
In [4]: str(response.ip_address)
Out[4]: '3.93.133.228'
CodePudding user response:
As you not mentioned complete code
, I'm suggesting this method...Have you tried post processing?
import re
ip = """(IPv4Address('79.127.127.87')"""
out = re.findall(r"'(.*?)'", ip, re.DOTALL)
#print(out)
#print(type(out))
ip_final = s = ''.join(out)
print(ip_final)
output
79.127.127.87