<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pass a list into requests.get() in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194442#M14921</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! That was it. There's a problem now with the URL in this script. I've posted another question about here:&amp;nbsp; &lt;A href="https://community.esri.com/thread/251431-missingschema-invalid-url-no-schema-supplied"&gt;https://community.esri.com/thread/251431-missingschema-invalid-url-no-schema-supplied&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Apr 2020 14:15:37 GMT</pubDate>
    <dc:creator>JaredPilbeam2</dc:creator>
    <dc:date>2020-04-13T14:15:37Z</dc:date>
    <item>
      <title>pass a list into requests.get()</title>
      <link>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194440#M14919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This gets one URL and prints it in XML format.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; requests
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; bs4 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; BeautifulSoup

url &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'''https://secure.shippingapis.com/ShippingAPI.dll?API=Verify&amp;amp;XML=
          &amp;lt;AddressValidateRequest USERID="564WILLC0589"&amp;gt;&amp;lt;Address&amp;gt;&amp;lt;Address1&amp;gt;
          2451 Avalon Ct&amp;lt;/Address1&amp;gt;&amp;lt;Address2&amp;gt;&amp;lt;/Address2&amp;gt;&amp;lt;City&amp;gt;Aurora&amp;lt;/City&amp;gt;
          &amp;lt;State&amp;gt;IL&amp;lt;/State&amp;gt;&amp;lt;Zip5&amp;gt;&amp;lt;/Zip5&amp;gt;&amp;lt;Zip4&amp;gt;&amp;lt;/Zip4&amp;gt;&amp;lt;/Address&amp;gt;&amp;lt;/AddressValidateRequest&amp;gt;'''&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#get the webpage&lt;/SPAN&gt;
response &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; requests&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#see if the URL has been correctly encoded&lt;/SPAN&gt;
r_url &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; response&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;text

&lt;SPAN class="comment token"&gt;#parse the downloaded page to get a beautifulsoup object&lt;/SPAN&gt;
new_xml &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; BeautifulSoup&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r_url&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; features &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"xml"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;prettify&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;new_xml&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&amp;gt;&amp;gt;&amp;gt; 
&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;AddressValidateResponse&amp;gt;
 &amp;lt;Address&amp;gt;
  &amp;lt;Address2&amp;gt;
   2451 AVALON CT
  &amp;lt;/Address2&amp;gt;
  &amp;lt;City&amp;gt;
   AURORA
  &amp;lt;/City&amp;gt;
  &amp;lt;State&amp;gt;
   IL
  &amp;lt;/State&amp;gt;
  &amp;lt;Zip5&amp;gt;
   60503
  &amp;lt;/Zip5&amp;gt;
  &amp;lt;Zip4&amp;gt;
   8574
  &amp;lt;/Zip4&amp;gt;
 &amp;lt;/Address&amp;gt;
&amp;lt;/AddressValidateResponse&amp;gt;
&amp;gt;&amp;gt;&amp;gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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 &lt;A href="https://webapp.willcountyillinois.com/Requests/USPSAPIWCHDUpdateAll.txt" rel="nofollow noopener noreferrer" target="_blank"&gt;text file&lt;/A&gt;.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#text file that has all the URLs&lt;/SPAN&gt;
txtfile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\Users\jpilbeam\USPSAPIWCHDUpdateAll.txt'&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#convert text file into a list&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; open &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txtfile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; f&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    x &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;list&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;map&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;str&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strip &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;readlines&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:44:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194440#M14919</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-12-11T09:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: pass a list into requests.get()</title>
      <link>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194441#M14920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If x is a list of URL strings from the text file, you just iterate over x passing each value to requests and printing it: &lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;for i in x:
    response = requests.get(i)
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:44:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194441#M14920</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T09:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: pass a list into requests.get()</title>
      <link>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194442#M14921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! That was it. There's a problem now with the URL in this script. I've posted another question about here:&amp;nbsp; &lt;A href="https://community.esri.com/thread/251431-missingschema-invalid-url-no-schema-supplied"&gt;https://community.esri.com/thread/251431-missingschema-invalid-url-no-schema-supplied&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Apr 2020 14:15:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pass-a-list-into-requests-get/m-p/194442#M14921</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2020-04-13T14:15:37Z</dc:date>
    </item>
  </channel>
</rss>

