title: Scrape parameters in the onclick function using python
body: <p>I've been trying to scrape a website using python but I'm not able to scrape the parameters in the onclick function.
  HTML is as follows</p>
  <pre><code>&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;1&quot; class=&quot;tabsborder2&quot;&gt;
      &lt;tbody&gt;&lt;tr class=&quot;cleft-link1&quot; height=&quot;20&quot;&gt;
        &lt;td width=&quot;3%&quot;&gt;S/N&lt;/td&gt;
         &lt;td width=&quot;20%&quot;&gt;Generic / Quantity&lt;/td&gt;
         &lt;td width=&quot;3%&quot;&gt;Type&lt;/td&gt;
        &lt;td width=&quot;10%&quot;&gt;Package Unit&lt;/td&gt;
        &lt;td width=&quot;9%&quot;&gt;Price(In Rs.)&lt;/td&gt;
        &lt;td width=&quot;9%&quot;&gt;Available Brands&lt;/td&gt;
        &lt;/tr&gt;
      
        
       &lt;tr class=&quot;row&quot;&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;1&lt;/td&gt;
        &lt;td valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;Aminophylline : 225 mg&lt;/td&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;
        Tablet &lt;/td&gt; 
         
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;10 Tablet&lt;/td&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;5.09&lt;/td&gt;
        
        
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;
  
  
         
                      
        &lt;a href=&quot;#&quot; onclick=&quot;MM_openBrWindow(&amp;#39;searching_list_brands_npp.php?qty=959@225 mg&amp;amp;gcount=1&amp;#39;,&amp;#39;&amp;#39;,&amp;#39;scrollbars=yes,width=800,height=600&amp;#39;)&quot;&gt;&lt;img src=&quot;./__Welcome to Medguideindia.com____ Your Ultimate Medicine Guide_files/brand_icon.GIF&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
                
        &lt;/td&gt;  
                  
        
            
      &lt;/tr&gt;
        
       &lt;tr class=&quot;row&quot;&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;2&lt;/td&gt;
        &lt;td valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;Vit E : 100 mg&lt;/td&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;
        Capsule &lt;/td&gt; 
         
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;10 Capsule&lt;/td&gt;
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;5.34&lt;/td&gt;
        
        
        &lt;td height=&quot;20&quot; valign=&quot;top&quot; class=&quot;mosttext&quot;&gt;
  
  
                      &lt;a href=&quot;#&quot; onclick=&quot;MM_openBrWindow(&amp;#39;searching_list_similar_brands.php?similarpid=131,259,315,666,944,1004,2955&amp;amp;qty=131@100 mg&amp;amp;gcount=1&amp;#39;,&amp;#39;&amp;#39;,&amp;#39;scrollbars=yes,width=800,height=600&amp;#39;)&quot;&gt;&lt;img src=&quot;./__Welcome to Medguideindia.com____ Your Ultimate Medicine Guide_files/brand_icon.GIF&quot; border=&quot;0&quot;&gt;&lt;/a&gt;   
                                 
            
        &lt;/td&gt;  
  </code></pre>
  <p>I was able to scrape the text in the td tag but they are not organised either.
  Code:</p>
  <pre><code>    
      page = requests.get(baseurl)
      soup = BeautifulSoup(page.content, 'html5lib')
      table = soup.find('table', attrs = {'class':'tabsborder2'})
  
      for row in table.find_all('tr', attrs = {'class':'row'}):
          m= {}
          names = soup.find_all('td', attrs = {'class':'mosttext'})
          for name in names:
              text = name.text
              m['Data'] = text
              
              response= Selector(text=names)
              link_id = response.xpath('//td/a[contains(@onclick, &quot;MM_openBrWindow&quot;)]/@onclick').re_first( r'&quot;([^&quot;]+)&quot;')
  
              df = df.append(m, ignore_index=True)
              
  </code></pre>
  <p>Issue 1(important)- How do I scrape the 1st parameters in the onclick function?
  Issue 2- I want to scrape the content and append them to a dataframe so that I can save it as a .csv file. But the text is getting appended to dataframe in different lines. I tried adding them to rows but it didn't work.</p>
  <p>Can someone suggest a way to solve it? Thanks is advance.</p>