This gets one URL and prints it in XML format.
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="keyword token">from</SPAN> bs4 <SPAN class="keyword token">import</SPAN> BeautifulSoup
url <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'''https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=
<AddressValidateRequest USERID="564WILLC0589"><Address><Address1>
2451 Avalon Ct</Address1><Address2></Address2><City>Aurora</City>
<State>IL</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>'''</SPAN>
<SPAN class="comment token">#get the webpage</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#see if the URL has been correctly encoded</SPAN>
r_url <SPAN class="operator token">=</SPAN> response<SPAN class="punctuation token">.</SPAN>text
<SPAN class="comment token">#parse the downloaded page to get a beautifulsoup object</SPAN>
new_xml <SPAN class="operator token">=</SPAN> BeautifulSoup<SPAN class="punctuation token">(</SPAN>r_url<SPAN class="punctuation token">,</SPAN> features <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xml"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>prettify<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>new_xml<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>>>>
<?xml version="1.0" encoding="utf-8"?>
<AddressValidateResponse>
<Address>
<Address2>
2451 AVALON CT
</Address2>
<City>
AURORA
</City>
<State>
IL
</State>
<Zip5>
60503
</Zip5>
<Zip4>
8574
</Zip4>
</Address>
</AddressValidateResponse>
>>><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
But, I have a list of URLs that need to be printed in XML format. Using this list how can I pass one item at a time into requests.get()? Link to text file.
<SPAN class="comment token">#text file that has all the URLs</SPAN>
txtfile <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\jpilbeam\USPSAPIWCHDUpdateAll.txt'</SPAN>
<SPAN class="comment token">#convert text file into a list</SPAN>
<SPAN class="keyword token">with</SPAN> open <SPAN class="punctuation token">(</SPAN>txtfile<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> f<SPAN class="punctuation token">:</SPAN>
x <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>list<SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">.</SPAN>strip <SPAN class="punctuation token">,</SPAN>f<SPAN class="punctuation token">.</SPAN>readlines<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>